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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Can javascript set a lookup value when all I have is the fieldname and value to set

(0) ShareShare
ReportReport
Posted on by 95

My plug-in returns data to my javascript webresource. Through Mapping definitions, I update Text fields, Optionsets, Date fields etc from raw text,- no problem.

However, to set values in Lookups I need to know the guid of the record to select in order to create an object containing fieldname, guid and value before calling: 

                window.parent.Xrm.Page.getAttribute(fieldName).setValue(object);

Trouble is, I don't know the guid.

I'm thinking I could write an oData query to find the guid (is there another way?!), but I don't think I can, using the one key piece of data I have (e.g. the name) reliably/consistently build a query filter for any lookup's related entity I may encounter, as the field names will vary.

Before I go too far with experimentation, is this likely to be achievable?

I have a server-side D365 Process which obtains the mappings and returns these to the javascript so maybe I could do something there to find the guid?

I have the same question (0)
  • Verified answer
    sdfasdf Profile Picture
    842 on at

    Hi,

    The only supported way to achieve what you need is by following the approach you already described: you'll have to query the API do get the record's GUID so that you can populate the lookup field. You might be able to write a generic function that takes the entity name and its default attribute's value (i.e. record's name), and use the WebAPI to look up the ID associated with that record.

    This article may be helpful: docs.microsoft.com/.../xrm-webapi

  • Chevva Profile Picture
    95 on at

    Thanks for the comment and confirming the only approach open to me.

    I opted for a generic server-side FetchXml routine to retrieve the guid and it works fine.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 55 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 37

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans