I am trying to populate the “From” look up field using custom JavaScript in Dynamics CRM.
I’m new to JavaScript and Dynamics really struggling to do this.
Below is a screenshot of my code and solution.
JavaScript
x
13
13
1
function PopulateFromLookUpField(executionContext) {
2
3
var formContext = executionContext.getFormContext();
4
5
var value = new Array(); //create a new object array
6
value[0] = new Object();
7
value[0].id = ; // set ID to ID
8
value[0].name = "new_name"; //set name to name
9
value[0].entityType = "sender"; //optional
10
formContext.getAttribute("sender").setValue(value);
11
12
}
13
I also tried the solution below it doesn’t work.
JavaScript
1
10
10
1
function PopulateFromLookUpField(executionContext) {
2
3
4
var lookUpObject.id = ;
5
lookUpObject.name = "Joe CRM";
6
lookUpObject.entityType = "sender";
7
formContext.getAttribute("sender").setValue(value);
8
9
}
10
Please advise and help.
Advertisement
Answer
I tried and this worked for me. Make sure to pass the correct field schema name, record GUID, record Name and entity Type properly.
JavaScript
1
7
1
var lookUpObject = new Array();
2
lookUpObject[0] = new Object();
3
lookUpObject[0].id = "7108f4e7-ac2b-eb11-a814-000d3a378f1b";
4
lookUpObject[0].name = "Arun Vinoth";
5
lookUpObject[0].entityType = "systemuser";
6
formContext.getAttribute("from").setValue(lookUpObject);
7