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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Get Lookup field Id

(0) ShareShare
ReportReport
Posted on by 805

Hello,

I am trying to get lookup field Id value from HTML WebResource using this statement:

let department = parent.Xrm.Page.getAttribute("department").GetValue()[0].id;

but got the following error: "Uncaught TypeError: parent.Xrm.Page.getAttribute(...).GetValue is not a function".

Am I missing something?

Microsoft Dynamics 365 Version 1710 (9.1.0.3245) online.

Regards,

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Charles Abi Khirs Profile Picture
    3,569 on at

    Hello Jaret,

    It should be .getValue() and not .GetValue()

    Hope this helps!

    If found helpful, please mark the answer as verified.

    Charles Abi Khirs.

  • ist Profile Picture
    805 on at

    Hi Charles,

    Thank you for your quick prompt!

    I fixed the function name. Now I got the following error message:

    0511.crm.png

    There is a business rule which hide Department field based on a condition. In my case Department field is hidden;

    In the debugger I see that getAttribute() returns a valid object, but getValue() returns null.

    I see also that getValue() checks whether the attribute Department is visible.

    Is it possible this error to be caused by the fact that the field is not visible?

    Regards,

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi,

    Please check following -

    1. There is a typo in GetValue , Here g  should be lowercase,   like getValue.

    1.As you said the lookup field is hidden , so did you assign any value in the lookup. If no then you should  check null before getting the I'd like below .

    var  department = parent.Xrm.Page.getAttribute("department").getValue();

    (department != null )

    {

    var deptid= department[0].id;

    }

    3. You need to Check the schema name of the lookup ,  might be  publisher name is  missing in the lookup field name( like new_fieldname)

    4. I have assign the lookup object in a var type

  • Verified answer
    Charles Abi Khirs Profile Picture
    3,569 on at

    In addition to the mentioned above, the below should be done:

    1. Check the lookup schema name.

    Most probably it is in the format "new_departmentid". The prefix "new" can be different based on the publisher used

    2. Check the existance of the lookup field and then verify that it contains a value.

    var  department = parent.Xrm.Page.getAttribute("new_departmentid");

    if(department != null ){

     var departmentValue = department.getValue();

     if(departmentValue != null){

       var departmenttId= departmentValue[0].id;

     }

    }

    Hope this helps!

    If found helpful, please mark the answer as verified.

    Charles Abi Khirs.

  • Suggested answer
    naresh babu Profile Picture
    425 on at

    Hi Jaret,

    Try this

    var ddl = document.getElementById("attributename").value;

    var lookUpItem =new Object();

    lookUpItem.id =ddl;

    lookUpItem.entityType ='new_test';

  • ist Profile Picture
    805 on at

    Thank you Guys,

    The problem was that the Department field had no value, because the JS responsible to fill in the field had a condition that checks form type == 1 (Create), although the form type was 2 (Update). This was a typo.

    Thanks once again Guys for your quick prompt and valuable comments and help.

    Regards.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans