locked
Set Party List field through Javascript RRS feed

  • Question

  • I am trying to set the Customers field of a new Service Activity form through Javascript. Here is my code:

     

     

    var customer = Xrm.Page.getAttribute("customerid").getValue();
    var customerid = "";
    if (customer != null)
    customerid = (customer[0].id);
    
     //set the parameters which say what is the ID of the parent type, the parent type (Case) and the title of the Parent entity
     var extraqs = "regardingobjectid="+Xrm.Page.data.entity.getId()
        + "&regardingobjecttypecode=incident&regardingobjectidname="
        + Xrm.Page.getAttribute("title").getValue();
    if(customerid != "") extraqs += "&customerid="+customerid+"&customeridname="+customer[0].name + "&customeridtype=" + customer[0].entityType;
     
     var serverUrl = "http://crm/org/main.aspx?etc=4214&pagetype=entityrecord&extraqs="
        +encodeURIComponent(extraqs);
    
    var leftPos = parseInt((screen.availWidth/2) - (1000/2));
     var topPos = parseInt((screen.availHeight/2) - (1000/2));
    
     window.open(serverUrl,"_blank", "location=no,menubar=no,status=no,toolbar=no,height=1000,width=1000,top="+topPos+",left="+leftPos+"",false);
    


    When I run this code, it throws an error. I am able to successfully set the regarding object for the activity, but I think since the field on the Service Activity form that holds the Customer record is called "customers" and is a Party List, this has to be done in another way.

    Anyone has an idea how this can be done?

     

    Tuesday, August 30, 2011 5:44 PM

Answers

  • According to microsoft , it's not possible.

    Have a look at this

    http://msdn.microsoft.com/en-us/library/gg334375.aspx 

     

    Here is extract from that article

    he following apply when setting the value of a lookup using a query string arguments to a form:

    • For simple lookups you must set the value and the text to display in the lookup. Use the suffix ‘name’ with the name of the attribute to set the value for the text.

      Do not use any other arguments.

    • For customer and owner lookups you must set the value and the name in the same way you set them for simple lookups. In addition you must use the suffix ‘type’ to specify the type of entity. Allowable values are ‘account’ or ‘contact’ and ‘systemuser’ or ‘team’.

    • You cannot set the values for partylist or regarding lookups.

    I hope this helps.


    Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/
    • Proposed as answer by Amreek Singh Wednesday, August 31, 2011 2:25 AM
    • Marked as answer by KatRiketa Wednesday, September 7, 2011 6:09 PM
    Wednesday, August 31, 2011 2:25 AM

All replies

  • Partlist fields don't take single Entity reference to set the value. they need an array of entity references.

    You are trying to set it to single lookup or entityreference.

     

    I hope this help.


    Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/
    • Proposed as answer by Amreek Singh Wednesday, August 31, 2011 2:11 AM
    Wednesday, August 31, 2011 2:10 AM
  • According to microsoft , it's not possible.

    Have a look at this

    http://msdn.microsoft.com/en-us/library/gg334375.aspx 

     

    Here is extract from that article

    he following apply when setting the value of a lookup using a query string arguments to a form:

    • For simple lookups you must set the value and the text to display in the lookup. Use the suffix ‘name’ with the name of the attribute to set the value for the text.

      Do not use any other arguments.

    • For customer and owner lookups you must set the value and the name in the same way you set them for simple lookups. In addition you must use the suffix ‘type’ to specify the type of entity. Allowable values are ‘account’ or ‘contact’ and ‘systemuser’ or ‘team’.

    • You cannot set the values for partylist or regarding lookups.

    I hope this helps.


    Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/
    • Proposed as answer by Amreek Singh Wednesday, August 31, 2011 2:25 AM
    • Marked as answer by KatRiketa Wednesday, September 7, 2011 6:09 PM
    Wednesday, August 31, 2011 2:25 AM
  • Thanks for the reply. I tried with:

     

    customers="+customerid+"&customersname="+customer[0].name + "&customerstype=" + customer[0].entityType;
    

    and

    customerid="+customerid+"&customeridname="+customer[0].name + "&customeridtype=" + customer[0].entityType;

    but I still get the same error.


    Thursday, September 1, 2011 8:23 PM
  • Another way of doing the same would be add code onload of sevice activity to check the parent entity and populate require field. For example I am populating regarding field with this code on Email:-

    if (crmForm.FormType == 1) {
        if (window.opener) {
            var oParentCrmForm = window.opener.document.all.crmForm;
            if (oParentCrmForm) {
                var sFormTypeName = oParentCrmForm.ObjectTypeName;
                if (sFormTypeName == "new_capaplan") {
                    var gRecordId = oParentCrmForm.ObjectId;
                    var sRecordName = oParentCrmForm.all.new_name.DataValue;
                    var lookupData = new Array();
                    var lookupItem = new Object();
                    lookupItem.id = gRecordId;
                    lookupItem.typename = sFormTypeName;
                    lookupItem.name = sRecordName;
    
                    lookupData[0] = lookupItem;
                    crmForm.all.regardingobjectid.DataValue = lookupData;
                }
            }
        }
    }
    


    Regards Faisal
    Thursday, December 8, 2011 5:05 PM
  • HI BREJJ

    Just wanted to set regarding field and your code works perfect for it. :)


    Haris Adil e-Bizsoft

    Thursday, July 19, 2012 2:11 PM