Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Answered

Cannot run the script to get lookup entity id.

Posted on by

Hello'

I have successfully run the onLoad webresource in Case form to get Subject entity's GUID through lookup field---subjectid. Now Subject entity is replaced by a custom entiy, named Category, my purperse is get the Category entity's GUID throught run a webresource when loading Case record. The code as below:

function getCategoryLookupId(executionContext) {

    debugger;

    var formContext = executionContext.getFormContext();

    var lookupObjValue = formContext.getAttribute("abc_opscategory").getValue();

    if (lookupObjValue != null) {

        var categoryId = lookupObjValue[0].id;

        if (categoryId != null) {

            Xrm.Utility.alertDialog("Category ID: " + categoryId);

        }
    }
}

When loading Case form, I have encounter an issue, lookupObjValue always is null. the screen as below

pastedimage1679025855588v1.png

Appreciated for your help!

  • ALAN365 Profile Picture
    ALAN365 on at
    RE: Cannot run the script to get lookup entity id.

    Stupide reason cause the "issue", LOL. --- The lookup field in Case form should have lookup record!!!

  • ALAN365 Profile Picture
    ALAN365 on at
    RE: Cannot run the script to get lookup entity id.

    Hi Leah,

    Thank you for your response. I've checked the lookup field logic name, it's correct and this custom lookup field and JS script are also located in same form, the issue still exist. In the same form an OOB lookup field "Subject", I can use same script to get Subject entity's GUID. The only different is one is custom entity, another one is OOB entity. What happen? Would you please give me advice?

  • Verified answer
    Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    RE: Cannot run the script to get lookup entity id.

    Hi Partner,

    Checking the logic name of the Category lookup column:

    pastedimage1679047166090v1.png

    Ans ensure that the Category lookup and js are added to the same form.

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,554 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,588 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans