locked
Help auto populating field based on lookout Value RRS feed

  • Question

  • I feel as though I'm missing something very basic. I want to auto populate a field using data selected from my lookout field. However when I select my data nothing happens. I've tested the code so I know that works, so I feel there's an issue with the way I'm implementing it. It's as if the onChange event doesn't occur.

    Here is my code for verification

    // Obtain value from contact field.
    var contactValue = new Array();
    contactValue = Xrm.Page.getAttribute("sgs_contact").getValue();
    if (contactValue != null) {
        var name = contactValue[0].name;
    }
    
    // Set value to Application Name
    Xrm.Page.getAttribute("sgs_applicationname").setValue(name);
    

    So my question is how do I implement this for the code to work? I feel like this is something so simple yet I'm overlooking it.

    Tuesday, November 5, 2013 8:48 PM

Answers

  • I was able to figure it out. Thanks to JLattimer I realized I actually need to call the function name in the OnChange event. I knew it was something simple like that. :)
    • Marked as answer by konioko Wednesday, November 6, 2013 12:20 AM
    Wednesday, November 6, 2013 12:20 AM

All replies

  • Something like this ties to the OnChange event of the Contact field would work:

    function OnChange() {
        var contact = Xrm.Page.getAttribute("sgs_contact").getValue();
        if (contact == null) {
            Xrm.Page.getAttribute("sgs_applicationname").setValue(null);
        }
        else {
            Xrm.Page.getAttribute("sgs_applicationname").setValue(contact[0].name);
        }
    }

    Keep in mind this code will only work when you are on the form and change the value, if you change the Contact value by some other means like a workflow or import - the JavaScript will not fire. 


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Tuesday, November 5, 2013 9:43 PM
    Moderator
  • I was able to figure it out. Thanks to JLattimer I realized I actually need to call the function name in the OnChange event. I knew it was something simple like that. :)
    • Marked as answer by konioko Wednesday, November 6, 2013 12:20 AM
    Wednesday, November 6, 2013 12:20 AM