Hi @Palani ,
Do you want to use the context.webAPI.updateRecord method to update LookUp field and Option Set type column in your Opportunity Entity?
Based on the formula that you mentioned, I think there is something wrong with it. Firstly, in order to get the guid value (accountid) of the selected account from the LookUp dialog launched using context.utils.lookupObjects method, please use the following formula:
selectedItem[0].id.guid
Note: The id attribute under the EntityReference object is also a Object value rather than a guid string value. Please check the following article for more details:
https://docs.microsoft.com/en-us/powerapps/developer/component-framework/reference/entityreference
For updating LookUp field (parentaccountid):
Actually, the LookUp field is a object value in underlying data structure of CDS Entity, it should contain the following two attributes:
logicalname
id
So you need to declare your oppForUpdate variable as below:
let oppForUpdate = {
"parentaccountid": {
"logicalname": "account",
"id": selectedItem[0].id.guid
}
}
or
let oppForUpdate = {
"parentaccountid@odata.bind": "/accounts(" + selectedItem[0].id.guid + ")"
}
Please check the following article for more details:
https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-webapi/updaterecord
So the whole formula should like below:
let oppForUpdate = {
"parentaccountid": {
"logicalname": "account",
"id": selectedItem[0].id.guid
}
};
this._context.webAPI.updateRecord("opportunity", recordGuid, oppForUpdate).then
(
function (updatedRecord: ComponentFramework.EntityReference) {
console.log("UpdateOpportunityRecord: Record updated successfully. ");
},
function (errorResponse: any) {
console.log("UpdateOpportunityRecord: Record update failed. " + errorResponse.toString());
}
);
Note: I assume that the parentaccountid LookUp field reference values from the Account Entity.
For updating Option Set field in your Opportunity Entity, I think your variable declare is correct. Combined with above feature, you should declare the oppForUpdate object as below:
let oppForUpdate = {
"parentaccountid": {
"logicalname": "account",
"id": selectedItem[0].id.guid
},
"statecode": 2,
"statuscode": 4
}
The whole formula should like below:
let oppForUpdate = {
"parentaccountid": {
"logicalname": "account",
"id": selectedItem[0].id.guid
},
"statecode": 2,
"statuscode": 4
};
this._context.webAPI.updateRecord("opportunity", recordGuid, oppForUpdate).then
(
function (updatedRecord: ComponentFramework.EntityReference) {
console.log("UpdateOpportunityRecord: Record updated successfully. ");
},
function (errorResponse: any) {
console.log("UpdateOpportunityRecord: Record update failed. " + errorResponse.toString());
}
);
or
let oppForUpdate = {
"parentaccountid@odata.bind": "/accounts(" + selectedItem[0].id.guid + ")",
"statecode": 2,
"statuscode": 4
};
this._context.webAPI.updateRecord("opportunity", recordGuid, oppForUpdate).then
(
function (updatedRecord: ComponentFramework.EntityReference) {
console.log("UpdateOpportunityRecord: Record updated successfully. ");
},
function (errorResponse: any) {
console.log("UpdateOpportunityRecord: Record update failed. " + errorResponse.toString());
}
);
Please check the following blog for more details:
https://somacrm.wordpress.com/2018/05/15/dynamics-365-xrm-webapi-update-record-example/
Please take a try with above solution, then check if the issue is solved.
Best regards,