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

Announcements

News and Announcements icon
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,985 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 107

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 53 Super User 2026 Season 1

#3
sannavajjala87 Profile Picture

sannavajjala87 29

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans