locked
CRM 2011: Populate email From field with a specific queue in javascript RRS feed

  • Question

  • How can i automatically populate the 'from' field in an email reply to an email message in a queue with the queue email address? I used this code from (http://www.resolvinghere.com/sm/how-can-i-populate-the-from-field-in-an-email-reply-to-an-email-message-in-a-queue-with-the-queue.shtml) but I am getting this error when the email loads in a particular queue: 

    "there was an error with this field's customized event crm 2011 event onload; object doesn't support property or method 'getAttributeValue' "

    Also here is the code:

    function CheckEnquiryReplyAddress() {
     // Only complete this validate on Create Form
     var formType = Xrm.Page.ui.getFormType();
     var emailStatus = Xrm.Page.getAttributeValue("statecode").getValue();
     var emailDirection = Xrm.Page.getAttributeValue("directioncode").getValue();
    
    
    
     if (formType == 1 || (formType == 2 && emailStatus == "Open")) {  
                                                 
                                           
      if (emailDirection == "1"){
      var previousEmailId=getExtraqsParam("_InReplyToId", window.parent.location.search);
    
       //getting context from the parent window
       var context = Xrm.Page.context;
    
       try {
        var serverUrl = context.getServerUrl();
        //The XRM OData end-point
        var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
        var query="/EmailSet?$select=ActivityId,ActivityTypeCode,DirectionCode,";
        query=query+"ToRecipients,Email_QueueItem/QueueId&$expand=Email_QueueItem&$filter=ActivityId eq guid'" + previousEmailId +"'";
        query =serverUrl+ODATA_ENDPOINT+ query;
    
        var request= new XMLHttpRequest();
        request.open("GET", query, false);
        request.setRequestHeader("Accept", "application/json");
        request.setRequestHeader("Content-Type", "application/json; charset=utf-8"); 
        request.onreadystatechange=function(){ CompleteEnquiryReplyCheck(request,serverUrl);}
        request.send(null);
       }
       catch(e) {
        alert(e.Description);
       }
      }
     }
    
              
    }
    function CompleteEnquiryReplyCheck(request,url)
    {
     if (request.readyState==4) {
      if(request.status==200) {
       var queue=JSON.parse(request.responseText).d.results[0];
       
       if (queue != null) {
        var queueId = queue.Email_QueueItem.results[0].QueueId.Id;
        var lookup = new Array();
          var lookupItem = new Object();
      
        lookupItem.id = queueId;
        lookupItem.name = queue.Email_QueueItem.results[0].QueueId.Name;
        lookupItem.typename = "queue";
         
        lookup[0] = lookupItem;
      
        Xrm.Page.getAttribute("from").setValue(lookup);
       }
      }
        }
    }

    Monday, April 11, 2016 4:06 PM

All replies

  • Hi,

    These two lines

    var emailStatus = Xrm.Page.getAttributeValue("statecode").getValue(); var emailDirection = Xrm.Page.getAttributeValue("directioncode").getValue();

    don't look too good, change the getAttributeValue to getAttribute....

    I'm not sure if you can set a activityparty field that way, but do try.

    Regards


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se


    Tuesday, April 12, 2016 11:48 AM
  • Hi Rickard,

    I tried but still getting the same error.

    Tuesday, April 12, 2016 6:25 PM
  • Hi Rickard, 

    I changed to getAttribute and I passed that error, now it doesn't like this line

      var previousEmailId=getExtraqsParam("_InReplyToId", window.parent.location.search);

    complaining at the getExtraqsParam 




    • Edited by Mitu-CRM Wednesday, April 13, 2016 12:32 PM
    Wednesday, April 13, 2016 12:32 PM
  • var emailStatus = Xrm.Page.getAttributeValue("statecode").getValue();

    change it to

    Xrm.Page.getAttribute("statecode").getValue();

    Also the statecode field needs to be placed on the form, for you to be able to read it. By default the statecode it not on the form, status reason is but that statuscode

    HTH

    Sam


    Dynamics CRM MVP | Inogic | http://www.inogic.com/blog | news at inogic dot com
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Proposed as answer by Sam - Inogic Friday, April 15, 2016 5:04 AM
    Friday, April 15, 2016 5:04 AM