Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Answered

Auto-Populate free text field with Lookup Value

Posted on by Microsoft Employee

Good morning all,

I'm trying to auto populate a free text field with the value of a lookup, i.e. populate Joe Smith in the free text field based on the look up value Joe Smith.

I've tried this code:

function AutoName(){

var ContactName = Xrm.Page.data.entity.attributes.get("new_contactnameid").getValue()[0].name;
var ContactNameId = Xrm.Page.data.entity.attributes.get("new_contactnameid").getValue()[0].id;
ContactNameId = ContactNameId.replace('{', '').replace('}', '');
var entityType = "contact";

var LookupValue = new Array();
LookupValue[0] = new Object();
LookupValue[0].id = ContactNameId;
LookupValue[0].name = ContactName;
LookupValue[0].entityType = entityType;

Xrm.Page.getAttribute("new_name").setValue(LookupValue);
}

For some reason I keep getting the error "invalidType".

Thanks in advance.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Auto-Populate free text field with Lookup Value

    Thanks Ravi, it worked!

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,406 on at
    RE: Auto-Populate free text field with Lookup Value

    Hi,

    try this-

    function AutoName(){

    var ContactName = Xrm.Page.data.entity.attributes.get("new_contactnameid").getValue()[0].name;

    Xrm.Page.getAttribute("new_name").setValue(ContactName);

    }

    Hope this helps.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,986 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,588 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans