Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Answered

JavaScript get Id of Lookup Field is blank

(0) ShareShare
ReportReport
Posted on by 18

Hi,

I am get the Id of the Lookup Field on the form with JavaScript. This code works with other Lookup fields on different forms, but not with this one. It is odd. The id field is blank which I have never seen before. 

JavaScript_5F00_ID_5F00_missing.png

  • Verified answer
    Wesley Nell Profile Picture
    65 on at
    RE: JavaScript get Id of Lookup Field is blank

    Hi,

    The issue above is that your field might not be on the form or have a value possibly. A good check to do is first get the field, then check if the field is null or undefined and then attempt the getValue() function after that check. So for example:

    var field = formContext.getAttribute("someField");
    
    if(field !== null || field !== undefined){
        var fieldValue = field.getValue();
        if(fieldValue !== null) {
            //do something with the value
        }
        else {
            //output and error alert or something else
        }
     }   
    //Shorthand check for value could be this as well
    var field = formContext.getAttribute("someField");
    var fieldValue = (field !== null || field !== undefined) ? field.getValue() : null;
    if(fieldValue !== null) {
        //do something with the value
    }
    else {
        //output and error alert or something else
    }

    Hope this helps. Please mark as verified if you have found that this is a solution.

  • Roddas77 Profile Picture
    18 on at
    RE: JavaScript get Id of Lookup Field is blank

    I have already tried that. I get the same result.

  • Suggested answer
    Bipin D365 Profile Picture
    28,961 Moderator on at
    RE: JavaScript get Id of Lookup Field is blank

    Hi,

    Not sure if this works but give it a try...

    Remove field from the form and then publish your changes. Now again add the same field on the form and publish the changes.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,025 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,837 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans