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 365 | Integration, Dataverse...
Answered

Is it possible to clear a lookup value using Xrm.WebApi.online.executeMultiple?

(0) ShareShare
ReportReport
Posted on by 5

Hi,

Is it possible to clear a lookup value using Xrm.WebApi.online.executeMultiple?

Please provide an example.

I have the same question (0)
  • Verified answer
    Pankaj Gogoi Profile Picture
    3,177 on at

    Hi Michel,

    You can use JS to clear lookup values

    formContext.getAttribute("new_field").setValue(null);

    if you are looking for CRUD operations using executeMultple, please refer the articles below.

    https://ryanjames.dev/blog/2019/09/16/crud-operations-with-xrm-webapi-online-execute-and-executemultiple/

    https://www.inogic.com/blog/2019/07/how-to-perform-multiple-crud-operations-using-executemultiple-web-api-request-in-dynamics-365-crm/

    https://www.msdynamicduo.com/post/how-to-clear-lookup-values-on-updates-using-the-new-cds-connector

    Best Regards

    PG

  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    You will need to use Delete request to clear lookup field value.

    See below article.

    www.inogic.com/.../

    As above link is only for one record, you could add this in executemultiple request as well for multiple records.

    Please mark my answer verified if i were helpful

  • Suggested answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi Partner,

    May I know  that why you need to clear lookup value using Xrm.WebApi?

    "Xrm.WebApi.online.executeMultiple" is usually used to execute many actions like CRUD, functions in other libraries or other actions. 

    If you want to clear a field, here are the two situations.

    1.This JS code is running in the entity form which contains the  lookup field, in this case, you could use formContext.getAttribute().setValue() to clear the field value.

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/attributes/setvalue

    2.This JS code is running in the entity form which does not contain the lookup field, if there are relationships between the 2 entities, you should get the related record is first by the look field first and then use webapi.updateRecord to clear its look up field.

    For example, I want to clear lookup field A on account form but my JS code will run on Contact form, So I need to get the account id first from contact form by "CompanyName" and then use the accountid to update itself.

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-webapi/updaterecord

    3.This JS code will be triggered by custom ribbons, as the above, you need to get the record id first by retrieveRecord with filter conditions and then use  webapi.updateRecord  to update it.

    Regards,

    Leo

  • Michel Fleitas Profile Picture
    5 on at

    I forgot to mention, I cannot use the form context, is a webresource that is showing a grid of records.

  • Verified answer
    Viswanath Profile Picture
    93 on at

    This might help somone in future. so replying. the below code clears the lookup in the related record.

    var data = {

               "_new_invoice_value@odata.bind": null,

           }

           Xrm.WebApi.updateRecord("opportunity", opportunityId, data).then(

               function success(result) {

                   console.log("Updated opportunity : " + opportunityId);

               },

               function (error) {

                   console.log(error.message);                

               }

           );

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 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 74

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans