I'm trying to create a reusable javascript function that sets the "Name" of the current record based on a few supplied parameters that dictate which columns to concatenate from a lookup record on the form.
When the lookup is cleared, the "Name" is null'd. When the lookup is selected, I do an Xrm.WebApi call to get the lookup entity. I then find the fields named in the function parameters, get their values, concatenate them, then set the form entity "Name" field to this value. Everything works fine. I can call this from any lookup control's onchange event.
To make this more reusable though, I'd like a way to dynamically get the PrimaryName field attribute (or it's logical name) from the current entity. My current solution is to pass the logical name of the field as an additional parameter. Easy enough. But I'd really like to do this step dynamically. Any suggestions?