cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
biswa07
Frequent Visitor

While saving patch in lookup getting error

Patch('List Employee Details',{ID:ThisItem.ID},{Title:txtTitle.Text,'Employee Name':txtEmployeeName.Text,'Employee Address':txtEmployeeAddress.Text,'Employee Contact':txtEmployeeContact.Text
,'Marital Status':LookUp('List Marital Status','Marital Status1'=ddlMaritalStatus.Selected.Title,ID)
});

Here 1st 'Marital Status' is destinatination list field name .

'List Marital Status' is Datasource name.

2nd 'Marital Status' is list coumn name from the data gets filled in dropdown .
'ddlMaritalStatus' is dropdown .



Here in 'List Employee Details' list I hve lookup the 'List Marital Status' list field 'Marital Status' .


Error : 
the type of this argument 'Marital_x0020_Status' does not match the expected type record , found type number .

Please help . 

Thanks .

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@biswa07 

What type of DataSource are you using?  SharePoint, Excel, SQl, other?

 

I'm assuming SharePoint...

What type of column is the Marital Status column?  A choice or a lookup or a text?

If it is a text column, then yes, this will fail.  Here because you are trying to assign an entire record from the Lookup, to the Marital Status column, AND, you are giving a default value (if the lookup does not find a record) of ID which is numeric.  You would need to put a ".something" on the end of your lookup to grab the actual value you want from whatever column you want:

 

Patch('List Employee Details',{ID:ThisItem.ID},{Title:txtTitle.Text,'Employee Name':txtEmployeeName.Text,'Employee Address':txtEmployeeAddress.Text,'Employee Contact':txtEmployeeContact.Text
,'Marital Status':LookUp('List Marital Status','Marital Status1'=ddlMaritalStatus.Selected.Title,ID).SomeColumn
});

 

 

Is this a Choice column?  Then you will need to do a little extra to assign the value.

 

Patch('List Employee Details',{ID:ThisItem.ID},{Title:txtTitle.Text,'Employee Name':txtEmployeeName.Text,'Employee Address':txtEmployeeAddress.Text,'Employee Contact':txtEmployeeContact.Text
,'Marital Status': {
Value:LookUp('List Marital Status','Marital Status1'=ddlMaritalStatus.Selected.Title).SomeColumn,
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference"
}});

 

 

If this is a lookup reference to another List, then there is one more piece needed:

 

Patch('List Employee Details',{ID:ThisItem.ID},{Title:txtTitle.Text,'Employee Name':txtEmployeeName.Text,'Employee Address':txtEmployeeAddress.Text,'Employee Contact':txtEmployeeContact.Text ,
'Marital Status': { Value:LookUp('List Marital Status','Marital Status1'=ddlMaritalStatus.Selected.Title).SomeColumn,
Id: Lookup('List Marital Status','Marital Status1'=ddlMaritalStatus.Selected.Title).ID '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference"
}

});

 

 

Ideally, you can have the records of your DropDown list contain all of these items so that you can just reference them in the Patch without using Lookup's, but that's a different topic.

This should get you going - if again, this is a SharePoint list.

 

Hope this helps.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

7 REPLIES 7
RandyHayes
Super User
Super User

@biswa07 

What type of DataSource are you using?  SharePoint, Excel, SQl, other?

 

I'm assuming SharePoint...

What type of column is the Marital Status column?  A choice or a lookup or a text?

If it is a text column, then yes, this will fail.  Here because you are trying to assign an entire record from the Lookup, to the Marital Status column, AND, you are giving a default value (if the lookup does not find a record) of ID which is numeric.  You would need to put a ".something" on the end of your lookup to grab the actual value you want from whatever column you want:

 

Patch('List Employee Details',{ID:ThisItem.ID},{Title:txtTitle.Text,'Employee Name':txtEmployeeName.Text,'Employee Address':txtEmployeeAddress.Text,'Employee Contact':txtEmployeeContact.Text
,'Marital Status':LookUp('List Marital Status','Marital Status1'=ddlMaritalStatus.Selected.Title,ID).SomeColumn
});

 

 

Is this a Choice column?  Then you will need to do a little extra to assign the value.

 

Patch('List Employee Details',{ID:ThisItem.ID},{Title:txtTitle.Text,'Employee Name':txtEmployeeName.Text,'Employee Address':txtEmployeeAddress.Text,'Employee Contact':txtEmployeeContact.Text
,'Marital Status': {
Value:LookUp('List Marital Status','Marital Status1'=ddlMaritalStatus.Selected.Title).SomeColumn,
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference"
}});

 

 

If this is a lookup reference to another List, then there is one more piece needed:

 

Patch('List Employee Details',{ID:ThisItem.ID},{Title:txtTitle.Text,'Employee Name':txtEmployeeName.Text,'Employee Address':txtEmployeeAddress.Text,'Employee Contact':txtEmployeeContact.Text ,
'Marital Status': { Value:LookUp('List Marital Status','Marital Status1'=ddlMaritalStatus.Selected.Title).SomeColumn,
Id: Lookup('List Marital Status','Marital Status1'=ddlMaritalStatus.Selected.Title).ID '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference"
}

});

 

 

Ideally, you can have the records of your DropDown list contain all of these items so that you can just reference them in the Patch without using Lookup's, but that's a different topic.

This should get you going - if again, this is a SharePoint list.

 

Hope this helps.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thank you.  I will try this.

I tried as mentioned , but data not saving .. please help .

 

Patch('List Employee Details',{ID:ThisItem.ID},{Title:txtTitle.Text,'Employee Name':txtEmployeeName.Text,'Employee Address':txtEmployeeAddress.Text,'Employee Contact':txtEmployeeContact.Text ,
'Marital Status': {
     Value:LookUp('List Marital Status','Marital Status'=ddlMaritalStatus.Selected.Title).'Marital Status',
     Id: LookUp('List Marital Status','Marital Status'=ddlMaritalStatus.Selected.Title).ID,
     '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference"
     }  
})

@biswa07 

In the 'List Employee Details' list - what type of column is 'Marital Status' ?

In the 'List Marital Status' list - what type of column is 'Marital Status'?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

In the 'List Employee Details' list - it is Lookup
In the 'List Marital Status' list - it is Single line of text

@biswa07 

At a glance...it all looks fine.  But wait, as I was writing this I looked over your formula again and see the issue.

Your Patch statement is all wrong - you're actually not even patching a record.

You need this:

Patch('List Employee Details', Lookup('List Employee Details', ID=ThisItem.ID),
{Title:txtTitle.Text,
'Employee Name':txtEmployeeName.Text,
'Employee Address':txtEmployeeAddress.Text,
'Employee Contact':txtEmployeeContact.Text, 'Marital Status': { Value:LookUp('List Marital Status','Marital Status'=ddlMaritalStatus.Selected.Title).'Marital Status', Id: LookUp('List Marital Status','Marital Status'=ddlMaritalStatus.Selected.Title).ID, '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference" } }
)

As you see in the above formula, you NEED to provide the record that is going to be patched.  In this case, a Lookup of that Record will give what we need for Patch to work.

If you were creating a New record, you would substitute the Lookup with Defaults('List Employee Details').

 

Make that change and your problem should be solved.

Hope that helps.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Fixed the issue by changing the - 

ddlMaritalStatus.Selected.Title

to 

ddlMaritalStatus.Selected.Value

 Thank you for your help .

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,319)