locked
CRM 2013 JavaScript - Get the customerid (lookup field value) from Quote and set it to Contact Entity field --> parentcustomerid field (lookup field) RRS feed

  • Question

  • Hi CRM Folks,

    I am trying to build a JS which will do the following:

    1. Get the customerid lookup field value from the Quote Entity. (customerid lookup field on Quote Entity form) ---working fine.

    2. Quote entity has a Contact subgrid and the Contact Entity parentcustomerid lookup field (Parent Account).

    3. Set the customerid look up value ----> parentcustomerid (Parent Account) lookup field. 

    I have used the following JS:

    function getlookup()
    {
    var lookupObject = Xrm.Page.getAttribute("customerid");
    if (lookupObject != null)
    {
    var lookUpObjectValue = lookupObject.getValue();
    if ((lookUpObjectValue != null))
    {
    var lookuptextvalue = lookUpObjectValue[0].name;
    alert(lookuptextvalue);
    var lookupid = lookUpObjectValue[0].id;
    alert(lookupid);
    Xrm.Page.getAttribute("parentcustomerid").setValue(lookuptextvalue);
    }
    }
    }

    I am getting the parent lookup value but the code is not setting the lookup value for Contact Entity - parentcustomerid lookup field (Parent Account)


    • Edited by Umes Kumar Monday, May 11, 2015 12:13 AM
    Sunday, May 10, 2015 11:40 PM

All replies

  • Hi Rick,

    Try the following code.

    function getlookup() {
        var lookupObject = Xrm.Page.getAttribute("customerid");
        if (lookupObject != null) {
            var lookUpObjectValue = lookupObject.getValue();
            if ((lookUpObjectValue != null)) {
                var lookuptextvalue = lookUpObjectValue[0].name;
                alert(lookuptextvalue);
                var lookupid = lookUpObjectValue[0].id;
                alert(lookupid);
                Xrm.Page.getAttribute("parentcustomerid").setValue(lookupObject);
            }
        }
    }

    Gopinath

    http://mscrmtechie.blogspot.in/

    Monday, May 11, 2015 8:48 AM
  • Thank for replying Gopinath....but this ain't working. 

    I have already tried the above  It's displaying the error that attribute is null...

    There's a connection grid on my page which contains the contact Entity.

    Regards

    Rick

    Thursday, May 14, 2015 3:11 AM
  • Setting lookups requires that you create an object, then set the ID and Name, then set the new lookup to the object.

    This Blog shows a good example of how to do it.

    http://www.mscrmconsultant.com/2012/08/get-and-set-lookup-value-using.html

    Thursday, May 14, 2015 5:55 PM
  • Hi Chris,

    Thanks for replying.

    I have tried every option and came to a conclusion that  I have to use oData Query or Post Event Plugin.

    Cheers

    Rick

    Thursday, May 28, 2015 9:44 PM
  • function getlookup() { var lookupObject = Xrm.Page.getAttribute("customerid"); if (lookupObject != null) { var lookUpObjectValue = lookupObject.getValue(); if ((lookUpObjectValue != null)) { var lookuptextvalue = lookUpObjectValue[0].name; alert(lookuptextvalue); var lookupid = lookUpObjectValue[0].id; alert(lookupid); Xrm.Page.getAttribute("parentcustomerid").setValue(lookUpObjectValue); } } }

    Didn't this work for you Rick?? Strange.

    I worked on the same few months ago and I got it working fine.


    Jugal Kishore Dandamudi.

    Friday, May 29, 2015 5:51 AM