E.g., while creating a phone call record in Dynamics 365 we have a regarding field which is related as a parent entity to phone call. Now let’s assume we are creating phone call for a lead and trying to capture its status on creation on phone call form.
In order to achieve, we have to install “CRM Rest Builder” solution in the current environment.
Use the following link to download CRM Rest Builder Solution:
First, we must check if phone call regarding has a value or not.
if (formContext.getAttribute(“regardingobjectid”) != null && formContext.getAttribute(“regardingobjectid”).getValue() != null && formContext.getAttribute(“regardingobjectid”).getValue().length > 0)
Then we have to check if regarding entity is lead nor not.
var regarding = formContext.getAttribute(“regardingobjectid”).getValue().entityType;
if (regarding == “lead”)
We have to fetch form type and check if it is a create or not.
var formType = formContext.ui.getFormType();
if (formType == 1)
We have to get the GUID of the regarding lead.
var regardingId = formContext.getAttribute(“regardingobjectid”).getValue().id;
var newid = regardingId.slice(1, -1);
Now with lead GUID we need to fetch status field from lead and then set it on to phone call form.
For this open solution in D365, after installing CRM Rest Builder we’ll have an option to open it on top left corner.
Based on requirement we’ll select options available as:
Endpoint: Web API 9.1 v9.2.21091.126
Action: Retrieve Single
Output Format: XMLHTTP
Formatted Values: Yes
Detect Changes: No
Token Header: No
Primary Entity: <Select Lead>
Id to Retrieve: <Provide random GUID for time being>
Field to Select: <Select Status>
Then click on “Create Request”
In order to update static GUID with regarding phone call GUID, we have already defined a variable “newid” to store the same.req.open(“GET”, Xrm.Page.context.getClientUrl() + “/api/data/v9.1/leads(” + newid + “)?$select=statecode”, true);
In success condition, if(this.statue === 200)
Write set value statement to set value of status record on phone call.
With this we have picked GUID of a record and fetched its attributes and updated it in current record.