there's a case entity that has a lookup field
i want to set in that field a the same lookup thats been set in a contact entity's lookup field in javascript
how do i do that ?
there's a case entity that has a lookup field
i want to set in that field a the same lookup thats been set in a contact entity's lookup field in javascript
how do i do that ?
One of the Best answering to a question i've seen
thank you very much
Hi Partner,
The Contact entity and Case entity is 1:N relationship, so you want to copy parent's lookup field value to child's lookup field value, right?
A Lookup field type represents the relationship attribute on the related entity.
Required Attributes of lookup fields:
id: The GUID of the item. Required for set.
name: The name of the item to be displayed. Required for set.
entityType: The entity name of the item. Required for set.
Scenario: Custom entity both has 1:N relationship with Contact and Case, they both show as custom lookup field in the form:
Code:
function setLookup(executionContext) { var formContext = executionContext.getFormContext(); var contact = formContext.getAttribute('customerid').getValue()[0].id.slice(1, -1);//get Contact id if (contact != null) { //use contact id to retrieve it to get custom lookup field value Xrm.WebApi.online.retrieveRecord("account", "" contact "", "?$select=_new_customid_value").then( function success(result) { var _new_customid_value = result["_new_customid_value"]; var _new_customid_value_formatted = result["_new_customid_value@OData.Community.Display.V1.FormattedValue"]; var _new_customid_value_lookuplogicalname = result["_new_customid_value@Microsoft.Dynamics.CRM.lookuplogicalname"]; if (_new_customid_value != null) { var value = new Array(); value[0] = new Object(); value[0].id = _new_customid_value; value[0].name = _new_customid_value_formatted; value[0].entityType = _new_customid_value_lookuplogicalname; formContext.getAttribute("new_customid").setValue(value); //set the custom lookup field value in case } else { alert("No Contact"); } }, function (error) { Xrm.Utility.alertDialog(error.message); } ); } }
Test:
Note:
Using CRM REST Builder to build retrieve code easily: https://github.com/jlattimer/CRMRESTBuilder
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,269 Super User 2024 Season 2
Martin Dráb 230,198 Most Valuable Professional
nmaenpaa 101,156