suttonb1
suttonb1

Reputation: 353

Update Dynamics form field when item is selected on another field

I have a Dynamics entity that has a relationship to another entity with a Main form in UX. I have a lookup control on the form to select that related entity. Doing so correctly writes the ID of that related entity record to the current record being edited. I need help grabbing the name value of that linked entity and writing it to the name value of the current record when the lookup selection changes. The form designer makes this so much more difficult than it needs to be! Is there a set of basic jscript libraries that I can add to my solution and call for such simple tasks?

Upvotes: 0

Views: 1258

Answers (1)

suttonb1
suttonb1

Reputation: 353

After literally HOURS of hunting down bits and pieces, I finally got this to work!

function updateName(){
 var name = "";
 var lookupField = Xrm.Page.getAttribute("lookupentityproperty");

 // Verify the field does exist on the form and has a selected value
 if (lookupField != null && lookupField.getValue() != null && lookupField.getValue()[0] != null) {
      name = lookupField.getValue()[0].name;
 }
 else { name = null; }

 var nameField= Xrm.Page.getAttribute("nameproperty");
 nameField.setValue(name);
}

Upvotes: 1

Related Questions