Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Get Field id

Posted on by 760

Hi ,

I'm trying to set a default value for a lookup field. I keep on seeing "fieldid" in the suggested script.

How will I know the field id of a certain field?

*This post is locked for comments

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Get Field id

    I use the following function to set the value of a lookup field (usually in a globals file):

    function setLookupField(fieldName, lookupId, lookupName, entityName) {

       var lookupData = new Array();

       var lookupItem = new Object();

       lookupItem.id = lookupId;

       lookupItem.name = lookupName;

       lookupItem.entityType = entityName;

       lookupData[0] = lookupItem;

       Xrm.Page.getAttribute(fieldName).setValue(lookupData);

    }

    You then just call the function where you need it:

    setLookupField("FIELD_LOGICAL_NAME", "GUID_OF_LOOKUP", "TEXT_THAT_GOES_IN_LOOKUP", "NAME_OF_ENTITY");

    Example:

    setLookupField("new_FieldId", "4AB26754-3F2F-4B1D-9EC7-F8932331567A", "Sample Project", "account");

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get Field id

    Hi Arci,

    if you solved the problem thanks to an answer, please mark it as verified to encourage the community to provide more and more a better support. Thank you. Francesco

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Suggested answer
    Syed Ibrahim Profile Picture
    Syed Ibrahim 6,257 on at
    RE: Get Field id

    You can try

    var name = Xrm.Page.getAttribute('<FIELD_NAME>').getValue()[0].name;

    (you can also use "id":  Xrm.Page.getAttribute('<FIELD_NAME>').getValue()[0].id;)

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Get Field id

    Hi Arci,

    You need to go to Setting >> Customization >> Customize The System >> your entity >> fields >> This will list out the field along with their schema name. Look for you field and then use the schema name in your code.

    For example, if you want to know the field id of Primary Contact of Account entity then go to Setting >> Customization >> Customize The System >> Account >> Primary Contact >> the schema name for Primary Contact is primarycontactid.  

    So to get this lookup, you need to write

    Xrm.Page.getAttribute("new_fieldid")

    Hope this helps

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get Field id

    Hi Arci,

    you could use the following methods to deal with lookup:

    // GET LOOKUP
    var lookup = Xrm.Page.getAttribute('XXXXXX').getValue();
    if (lookup != null) {
        var name = lookup[0].name;
        var id = lookup[0].id;
        var type = lookup[0].entityType;
    }
    
    // SET LOOKUP
    var lookup = [{}];
    lookup[0].id = recorid;
    lookup[0].name = recordname;
    lookup[0].entityType = entityname;
    Xrm.Page.getAttribute('XXXXXX').setValue(lookup);


    Please let us know.

    If you found the answer helpful, please mark as Verified 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Get Field id

    Hi,

    You are supposed to use

    Xrm.Page.getAttribute("new_fieldid").setValue(value);

    to set a value

    new_fieldid is your lookup field name (so you'll need to change it to match your field name)

    value is the value you are going to set there. There are lots of examples, here is just one of those:

    www.mscrmconsultant.com/.../get-and-set-lookup-value-using.html

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans