Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

best way to set parentcustomerid_account to null using web api

Posted on by 386

hi

Could you please advise on best way to set

parentcustomerid_account

to null using web api ?

thank you

*This post is locked for comments

  • RE: best way to set parentcustomerid_account to null using web api

    This is seriously messed up. If I would like to remove five lookup values I need to send five delete messages...

    I'm sad now.

  • slx Profile Picture
    slx 386 on at
    RE: best way to set parentcustomerid_account to null using web api

    Thank you for help, I have different issue now:

    Could you please help with the following scenario ? I am running this code to delete a reference parentcustomerid_account

    This is working successfully on DEV but when executed on different environment IFD / ADFS the request is 404 NOT FOUND

    Do you have any idea ? Thank you

    // [Org URI]/api/data/v8.2/contacts([contactid#])/parentcustomerid_account/$ref

    contact1Uri = httpClient.BaseAddress + web_api + "contacts(" + myReader.Value.ToString

    ().ToLower() + ")/parentcustomerid_account/$ref";

    HttpResponseMessage disassocResponse1 = await httpClient.DeleteAsync(contact1Uri);

    if (disassocResponse1.StatusCode == HttpStatusCode.NoContent)

    Status code is 404 = NOT FOUND

    Same code is successful on different environment

  • slx Profile Picture
    slx 386 on at
    RE: best way to set parentcustomerid_account to null using web api

    Thank you for your help, it was not straight forward for me

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: best way to set parentcustomerid_account to null using web api

    EDIT: just noticed you seem to have figured it out:)

    Hi,

     you don't need to send both guids to delete - as Scott mentioned, you just need to use this kind of url for the delete request:

    .../api/data/v8.2/contacts(CONTACTID)/parentcustomerid_account/$ref

  • slx Profile Picture
    slx 386 on at
    RE: best way to set parentcustomerid_account to null using web api

    I manage to get everything done in 2 steps

    - get account if for parentaccountid

    - send delete request for disassociation.

    Thank you for your help, it is not straight forward

                                   contact1Uri = httpClient.BaseAddress + "v8.0/contacts(" + myReader.Value.ToString().ToLower() + ")";

                                   //queryOptions = "?$select=fullname,annualincome&$expand=parentcustomerid_account($select=name)";

                                   queryOptions = "?$select=fullname&$expand=parentcustomerid_account($select=accountid,name)";

                                   HttpResponseMessage retrieveResponse1 = await httpClient.GetAsync(contact1Uri + queryOptions);

                                   if (retrieveResponse1.StatusCode == HttpStatusCode.OK) //200

                                   {

                                       retrievedContact1 = JsonConvert.DeserializeObject<JObject>(

                                           await retrieveResponse1.Content.ReadAsStringAsync());

                                       Console.WriteLine("Contact Fullname {0}", retrievedContact1.GetValue("fullname"));

                                       Console.WriteLine("Contact parentcustomerid_account {0}", retrievedContact1["parentcustomerid_account"]["accountid"]);

                                       contactToDissasociateUri = httpClient.BaseAddress + "v8.0/accounts(" + retrievedContact1["parentcustomerid_account"]["accountid"].ToString().ToLower() + ")/contact_customer_accounts/$ref?$id="+ httpClient.BaseAddress + "v8.0/contacts(" + myReader.Value.ToString().ToLower() + ")";

                                       HttpResponseMessage disassocResponse1 =

                                                    await httpClient.DeleteAsync(contactToDissasociateUri);

                                       if (disassocResponse1.StatusCode == HttpStatusCode.NoContent)

                                       {

                                           Console.WriteLine("Contact '{0}' dissociated from account '{1}'.",

                                               retrievedContact1["fullname"], retrievedContact1["parentcustomerid_account"]["name"]);

                                       }

                                       else

                                       {

                                           Console.WriteLine("Failed to disassociate entities for reason: {0}.",

                                               disassocResponse1.ReasonPhrase);

                                           throw new CrmHttpResponseException(disassocResponse1.Content);

                                       }

                                       Console.ReadKey();

  • slx Profile Picture
    slx 386 on at
    RE: best way to set parentcustomerid_account to null using web api

    Thank you for reply, looks like I need to send both guids:

    - contact id

    - account id ( that needs to be set to null)

    Probably I am too new to this ...

    The request should look like this

    "xxxx/.../contact_customer_accounts$ref?$id=xxx/.../contacts(guid_contact)"

    Which is very strange as I only need to set existing parent account to NULL, why do I need to send the existing value if that is going to be NULL anyway?

    Also, I have issue when I tried to extract existing value if you can help

    "?$select=fullname,annualincome&$expand=parentcustomerid_account($select=name)";

  • Suggested answer
    ScottDurow Profile Picture
    ScottDurow 50,177 on at
    RE: best way to set parentcustomerid_account to null using web api

    Hi,

    You have to send a DELETE request.

    E.g.

    DELETE [Organization URI]/api/data/v8.2/opportunities(00000000-0000-0000-0000-000000000001)/customerid_account/$ref

    From msdn.microsoft.com/.../mt607875.aspx

    It is a bit odd - but this is the way that the OData spec defines it should be done!

    Hope this helps

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