Skip to main content
Community site session details

Community site session details

Session Id :
Customer Service forum

How to set null in the Lookup fields using C# custom web api

(0) ShareShare
ReportReport
Posted on by

Hello Guys,

I am facing an issue that how to set null value in the Lookup field using c# web api.

I am using following code--

address["field schema name"] = null;

Its working fine when i use 2011 endpoint service to update the null but not with the custom c# web api.

Your help would be a great help.

Categories:
  • Community Member Profile Picture
    on at
    RE: How to set null in the Lookup fields using C# custom web api

    thanks

  • Verified answer
    Arun Vinoth Profile Picture
    11,615 Moderator on at
    RE: How to set null in the Lookup fields using C# custom web api

    You cannot set null to lookup using web api.

    Rather use DELETE verb for single valued navigation property.

    stackoverflow.com/.../7920473

  • Community Member Profile Picture
    on at
    RE: How to set null in the Lookup fields using C# custom web api

    yes folk, i have tried it and its not working and throwing the usual error "Object reference not set to an instance of an object" something like this which means its not accepting the either "" or null.

  • LeoAlt Profile Picture
    16,331 Moderator on at
    RE: How to set null in the Lookup fields using C# custom web api

    Hi partner,

    Have you tried the suggestions? How is the situation now?

    Best Regards

    Leo

  • Community Member Profile Picture
    on at
    RE: How to set null in the Lookup fields using C# custom web api

    this field is already containing some so i want to remove that data from the field that's why i need to set it as null

  • Suggested answer
    AllanDeCastro Profile Picture
    156 on at
    RE: How to set null in the Lookup fields using C# custom web api

    Hello,

    Why are you trying to specify this field is null ? If you have nothing to put in this field just delete the line. :) 

    (Maybe you will have some errors if specific development use this field after, but normally you have to handle this)

  • Suggested answer
    Dynamics365 Rocker Profile Picture
    7,755 on at
    RE: How to set null in the Lookup fields using C# custom web api

    Hi Shashikant,

    Please go through below link, It may help you:

    community.dynamics.com/.../254377

  • LeoAlt Profile Picture
    16,331 Moderator on at
    RE: How to set null in the Lookup fields using C# custom web api

    Hi partner,

    You could try "" (empty) instead of null.

    In addition, could you kindly share the error message?

    Hope it helps.

    Best Regards

    Leo

  • LeoAlt Profile Picture
    16,331 Moderator on at
    RE: How to set null in the Lookup fields using C# custom web api

    Hi partner,

    When using WebApi to update lookup field, we should add "@odata.bind" after field name.

    You could refer to samples of using WebApi with C#.

    WeChat-Screenshot_5F00_20181217142517.png

    Please try address["field name@odata.bind"] instead.

    Hope it helps.

    Best Regards

    Leo

  • Community Member Profile Picture
    on at
    RE: How to set null in the Lookup fields using C# custom web api

    thanks for the response,

    i am already using the @odata.bind in the schema name.

    If i am passing the Guid of the record the its being saved in the CRM but when i try to set it null by sending the null string then its throwing the error.

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

News and Announcements

Now Available: 2025 Release Wave 2

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Customer Service

Featured topics

Product updates

Dynamics 365 release plans