locked
CRM 2015 Not able to set lookup value, onload/onchange email entity RRS feed

  • Question

  • Below is the code 

    var id = Xrm.Page.data.entity.attributes.get("test_from").getValue()[0].id;
    var name = Xrm.Page.data.entity.attributes.get("test_from").getValue()[0].name;
    var entityType = "contact";

    if (id != null) {
      var lookupData = new Array(); 
      var lookupItem = new Object(); 
      lookupItem.id = id;
      lookupItem.name = name;
      lookupItem.entityType = entityType;
      lookupData.push(lookupItem); 

     // Set the value 
     Xrm.Page.getAttribute("from").setValue(lookupData); 

    Monday, July 4, 2016 1:20 PM

Answers

  • Hi,
     
    The “To” and “From” fields on email entity form are of type Activity party not a lookup.
     
    The activity party can be set by using below code:
     
    //function to set activity party
    function setActivityPartyList(fieldName, id, name, entityType) {
    if(Xrm.Page.getAttribute(fieldName)!=null&&Xrm.Page.getAttribute(fieldName)!=undefined){
      // Create a array
      var partyListArray = new Array();
      partyListArray[0] = new Object();
     
      partyListArray[0].id = id;
      partyListArray[0].name = name;
      partyListArray[0].entityType = entityType;
     
      //Set value array to field
      Xrm.Page.getAttribute(fieldName).setValue(partyListArray);
     
    }
    }
     
    Hope this helps
     
    Thanks!
    Sam

    Inogic | Blog | news@inogic.com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by FAKHRI09 Monday, July 10, 2017 9:57 AM
    Tuesday, July 5, 2016 12:29 PM

All replies

  • Try the below change;

      var lookupData = new Array(); 
      lookupData[0] = new Object(); 
      lookupData[0].id = id;
      lookupData[0].name = name;
      lookupData[0].entityType = entityType;

    Tuesday, July 5, 2016 10:39 AM
  • Hi,
     
    The “To” and “From” fields on email entity form are of type Activity party not a lookup.
     
    The activity party can be set by using below code:
     
    //function to set activity party
    function setActivityPartyList(fieldName, id, name, entityType) {
    if(Xrm.Page.getAttribute(fieldName)!=null&&Xrm.Page.getAttribute(fieldName)!=undefined){
      // Create a array
      var partyListArray = new Array();
      partyListArray[0] = new Object();
     
      partyListArray[0].id = id;
      partyListArray[0].name = name;
      partyListArray[0].entityType = entityType;
     
      //Set value array to field
      Xrm.Page.getAttribute(fieldName).setValue(partyListArray);
     
    }
    }
     
    Hope this helps
     
    Thanks!
    Sam

    Inogic | Blog | news@inogic.com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by FAKHRI09 Monday, July 10, 2017 9:57 AM
    Tuesday, July 5, 2016 12:29 PM