locked
CRM 2011: Default From and BCC fields not populating on replies RRS feed

  • Question

  • Hi All,

    I am using javascript to pre-populate the From and BCC fields in a project on the e-mail form.  It fills these with default corporate generic e-mail addresses.  The scripts are triggered on load of the form.  It works fine on all New e-mails, but it doesn't populate the fields for reply e-mails, this is the problem. 

    It uses a helper script to run a soap call to find the default the From and BCC fields (using the RetrieveMultipleByAttribute function), this part works fine.  Will a reply e-mail also be Form Type 1?  If not what other fields and criteria can I use to evaluate if the fields need populating with the default values?

    function PopulateBCCField()
    {

        //when creating a new email it finds the default 'E Records User' and inserts it into the BCC field

         if(Xrm.Page.ui.getFormType() == 1)
          {
              var conditions = new Array(1);
              conditions[0] = 'ded_erecordsuser,Equal,true';

             var results = new Array();
             results = RetrieveMultipleByAttribute('systemuser', conditions, 'systemuserid,fullname');

             if(results.length==1){

            var varFullName = results [0]. selectSingleNode('//q1:fullname').nodeTypedValue;
            var varId = results [0]. selectSingleNode('//q1:systemuserid').nodeTypedValue;

                var bccUser = new Array();
               bccUser [0] = new Object();
               bccUser [0].id = varId;
               bccUser [0].entityType = "systemuser";
               bccUser [0].name =varFullName;

              Xrm.Page.getAttribute("bcc").setValue(bccUser);

             }

            else {
                   if(results.length>1){
                            alert('Error. There is more than one E Records User in system');
                   }
                  else {
                             alert('Warning there are no E Records users selected in the system');
                  }
             }
       }
    }

    function PopulateFromField()
    {
        //when creating a new email it finds the default 'Email From User' and inserts it into the from field

         if(Xrm.Page.ui.getFormType() == 1)
          {
              var conditions = new Array(1);
              conditions[0] = 'ded_emailfromuser,Equal,true';

             var results = new Array();
             results = RetrieveMultipleByAttribute('systemuser', conditions, 'systemuserid,fullname');

             if(results.length==1){

            var varFullName = results [0]. selectSingleNode('//q1:fullname').nodeTypedValue;
            var varId = results [0]. selectSingleNode('//q1:systemuserid').nodeTypedValue;

                var  fromUser = new Array();
               fromUser [0] = new Object();
                fromUser [0].id = varId;
                fromUser [0].entityType = "systemuser";
                fromUser [0].name =varFullName;

              Xrm.Page.getAttribute("from").setValue(fromUser);

             }

            else {
                   if(results.length>1){
                            alert('Error. There is more than one Email From User in system');
                   }
                  else {
                             alert('Warning there are no Email From Users selected in the system');
                  }
             }
       }
    }

                      
    • Edited by M LINACRE Wednesday, February 13, 2013 10:26 PM clarified
    Wednesday, February 13, 2013 10:20 PM