Skip to content

Populate dynamics CRM Activity Type sender from field using custom JavaScript?

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.

The "From" field apparently this is Activity party type Sender

function PopulateFromLookUpField(executionContext) {

var formContext = executionContext.getFormContext();

var value = new Array(); //create a new object array
value[0] = new Object();
value[0].id = ; // set ID to ID
value[0].name = "new_name"; //set name to name
value[0].entityType = "sender"; //optional
formContext.getAttribute("sender").setValue(value);

}

I also tried the solution below it doesn’t work.

function PopulateFromLookUpField(executionContext) {


 var lookUpObject.id = ;
   lookUpObject.name = "Joe CRM";
   lookUpObject.entityType = "sender";               
   formContext.getAttribute("sender").setValue(value);
   
}

Please advise and help.

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.

var lookUpObject = new Array();
lookUpObject[0] = new Object();
lookUpObject[0].id = "7108f4e7-ac2b-eb11-a814-000d3a378f1b";
lookUpObject[0].name = "Arun Vinoth";
lookUpObject[0].entityType = "systemuser";               
formContext.getAttribute("from").setValue(lookUpObject);