Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

retrieve look up record name

Posted on by Microsoft Employee

i want to retrieve lookup record name if another field value change 

here is my scenario i have a look up field called candidate and another field name send-email type(two option field yes\no )when user click on send-email a message will pop up with the candidate name\id and entity type \here is what i have found and write.

function getLookupDetails() {
var lookupObj = Xrm.Page.getAttribute(ant_candidate); //Check for Lookup Object
if (lookupObj != null) {
var lookupObjValue = lookupObj.getValue();//Check for Lookup Value
if (lookupObjValue != null) {
var lookupEntityType = lookupObjValue[0].entityType, //To get EntityName
lookupRecordGuid = lookupObjValue[0].id, // To get record GUID
lookupRecordName = lookupObjValue[0].name; //To get record Name

if (lookupEntityType != null && lookupRecordGuid != null && lookupRecordName != null) {
Xrm.Utility.alertDialog("Entity Type : " + lookupEntityType + "\nRecord GUID : " + lookupRecordGuid + "\nRecord Name : " + lookupRecordName, null);
}
}
}
}

i got an error here is the error ReferenceError: getLookupDetails

please help Best Regards .

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: retrieve look up record name

    Thanks To Saad after he called me and de bugged the problem in with me step by step i realize what was wrong with the script the javascript library

    have double brackets on other functions

    here is my original javascript library before

    function onCloseCallback() {{

    var dateOfInterview =  Xrm.Page.getAttribute("ant_dateoftheinterview").getValue();

       var message= "Do you Really Want To Send An Email at"+dateOfInterview;

       Xrm.Utility.confirmDialog(message, yesCloseCallback, noCloseCallback)

    }

    function yesCloseCallback() {

       Xrm.Page.getAttribute("ant_arrangementemail").setValue(true);

    }

    function noCloseCallback() {

      Xrm.Page.getAttribute("ant_arrangementemail").setValue(false);

    }}

    ----------------------------------------------

    function getLookupDetails() {

    debugger;

    var lookupObj = Xrm.Page.getAttribute("ant_candidate").getValue(); //Check for Lookup Object

    var lookupEntityType = lookupObj[0].entityType, //To get EntityName

    lookupRecordGuid = lookupObj[0].id, // To get record GUID

    lookupRecordName = lookupObj[0].name; //To get record Name

    if (lookupEntityType != null && lookupRecordGuid != null && lookupRecordName != null) {

    Xrm.Utility.alertDialog("Entity Type : " + lookupEntityType + "\nRecord GUID : " + lookupRecordGuid + "\nRecord Name : " + lookupRecordName, null);

    }

    }

    you can notice i have 2 problems 1 is the double braces at the begining and the seconed one is the dashes between functions i removed them and every thing went fine

    all credit goes to Saad Akhtar. Really Appriciated

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: retrieve look up record name

    ok saad i have a skype for business account

    and here is my account id a.mezian@gogettersme.com

    Best Regards

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: retrieve look up record name

    Share your Skype id. I will have a look at it

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: retrieve look up record name

    Thanks Saad unfortunatly still having the same error ,i dont know maybe my scenario is wrong please i am setting the function on change of the send-email field to trigger and get the lookup info of the candidate look up field is this wrong i dont think so

    Best Regards

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: retrieve look up record name

    Hi Mezian,

    Your code is correct after above suggestions. It should work. Please clear your cache and try to run this in InPrivate window

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: retrieve look up record name

    well thanks for you answers guys it gives me ReferenceError: getLookupDetails is not defined at eval which i gusse is the same error 

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: retrieve look up record name

    Hello,

    Replace line

    var lookupObj = Xrm.Page.getAttribute(ant_candidate);

    with line

    var lookupObj = Xrm.Page.getAttribute("ant_candidate");

  • Suggested answer
    kyleknab Profile Picture
    kyleknab 517 on at
    RE: retrieve look up record name

    var lookupObj = Xrm.Page.getAttribute(ant_candidate); //Check for Lookup Object

    You need quotation marks around the name of your attribute...  Xrm.Page.getAttribute("ant_candidate");

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans