web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Customised button- ribbon

(3) ShareShare
ReportReport
Posted on by 22
I am working in a Dynamics CRM environment and need to fix an issue with a customized "copy" button in the ribbon for an entity. This functionality and is running through a JavaScript.
The functionality is failing for a lookup field in the entity, which was recently added. From my last question's response, I understood that lookup fields need to be handled in a different way because they are actually combination of three separate values.
I tried to follow the script posted in the link below which was for a similar requirement:
https://blog.infobitsoft.com/2020/04/how-to-get-and-set-lookup-field-using.html

But unfortunately, this didn't seem to work, when I added this code in the existing script, the button became unresponsive. Since I am not an expert in coding, I am unable to debug properly on my own. Is there any way I can fix this? 

Would appreciate a quick response, as this is a client issue.
I have the same question (0)
  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Moderator on at
    Hello User,
     
    Please refer below article which is having updated JS code.
     
    The article which you are referring, having deprecated api's.
     
     
    Sample Code:
     
    function setLookupField(formContext) {
        var lookupValue = [{
            id: "00000000-0000-0000-0000-000000000000", // GUID of the record
            name: "Record Name", // Display name of the record
            entityType: "account" // Logical name of the entity
        }];
        
        formContext.getAttribute("your_lookup_field").setValue(lookupValue);
    }
     
     
    function getLookupField(formContext) {
        var lookupField = formContext.getAttribute("your_lookup_field").getValue();
        
        if (lookupField) {
            console.log("Lookup Name: " + lookupField[0].name);
            console.log("Lookup ID: " + lookupField[0].id);
            console.log("Lookup Entity Type: " + lookupField[0].entityType);
        } else {
            console.log("Lookup field is empty.");
        }
    }
     
     
    Thank you,
    Amit Katariya
  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Moderator on at
    Are you still facing any issue ?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Hamza H Profile Picture

Hamza H 142 Super User 2026 Season 1

#2
Nagaraju_Matta Profile Picture

Nagaraju_Matta 128

#3
11manish Profile Picture

11manish 119

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans