Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Unable to Update Ownerid field of custom entity using odata Json call

(1) ShareShare
ReportReport
Posted on by

Hi,

I'm facing issue while updating ownerid field of an entity with team,using odata json call,

my code is as follows:

public async Task TestUpdateUsingJson()

{

var complaintcasedata = new new_complaintcase();

complaintcasedata = GetComplaintCaseStub();

var recordid = complaintcasedata.new_complaintcaseid;

JObject jsondata = new JObject();

jsondata["ownerid@odata.bind"] = "/teams(" + complaintcasedata.ownerid + ")";

var ComplaintCaseResult = await serviceRequestProcessor.Update(jsondata,recordid, "new_complaintcases");

}

in above code new_complaintcase is my custom entity,in which I'm trying to update ownerid with teams

GetComplaintCaseStub() method in above method has dummy data as follows:

private static new_complaintcase GetComplaintCaseStub()

{

var complaintCase = new new_complaintcase();

complaintCase.new_aduserguid = "8604b472-edff-48d2-b0e6-dc83f7e241a6";

complaintCase.new_businessareaid = "Customer Relations";

complaintCase.new_casestatus = 100000000;

complaintCase.new_complaintagainst = 100000000;

complaintCase.new_complaintcaseid = Guid.Parse("3E482AFB-2190-4D4D-8383-6E0D13697E3C");

complaintCase.new_complaintdate = DateTime.Now;

complaintCase.new_complaintraisedbytypes = "Customer";

complaintCase.new_customernames = "Mrs N Qiehsaw, Mr M Ogcfqyu";

complaintCase.new_departmentraisedby = "IT";

complaintCase.new_originalcomplaintdate = DateTime.Now;

complaintCase.new_outstandingtask = "";

complaintCase.new_primaryaccount = "10003225";

complaintCase.new_primaryelementwithsubcategoryandcategory = "Redemption, Fees incorrectly applied";

complaintCase.new_primaryloanaccount = new new_loan { new_loanid = Guid.Parse("96771835-9162-434B-B3D1-0B88B33DB379"), new_name = "10003225" };

complaintCase.new_requestmethod = 100000001;

complaintCase.new_rootcause = 99999999;

complaintCase.new_sendcorrespondence = true;

complaintCase.new_summary = "test";

complaintCase.new_teamownerreason = "test";

complaintCase.new_type = 100000000;

complaintCase.new_username = "ABC";

 

complaintCase.ownerid = new team { name = "Customer Relations", teamid =Guid.Parse("37f8b9a4-e7b9-e511-80fb-3863bb353f28"),businessunitid=Guid.Parse("c9635b80-e4b9-e511-80f9-3863bb34e990") };

 

return complaintCase;

}

and below is my odata update call

public async Task<string> Update(JObject entityTobeUpdated, Guid recordid, string clientURL)

{

 

var recordId = recordid.ToString();

try

{

//Create HttpClient object to send and receive Http Requests and Response

var httpClient = await _connectionManager.CreateHttpClient();

using (httpClient)

{

var jsonData = JsonConvert.SerializeObject(entityTobeUpdated);

HttpRequestMessage request = new HttpRequestMessage(new HttpMethod("PATCH"), new Uri(httpClient.BaseAddress + clientURL)) { Content = new StringContent(jsonData, System.Text.Encoding.UTF8, "application/json") };

 

var response = await httpClient.SendAsync(request);

//If the response is Successfully executed then it will return the value true

if (response.IsSuccessStatusCode)

{

var recordUrl = response.Headers.GetValues("OData-EntityId").FirstOrDefault();

var splitRetrievedData = recordUrl.Split('[', '(', ')', ']');

recordId = splitRetrievedData[1];

}

}

}

catch (Exception exception)

{

throw new CustomODataException(exception.Message, exception);

}

return recordId;

}

I'm getting error that "method is not allowed",so I'm unable to update my owner id with team...please help me where I'm going wrong!


*This post is locked for comments

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Unable to Update Ownerid field of custom entity using odata Json call

    Hello,

    Try to replace line

    jsondata["ownerid@odata.bind"] = "/teams(" + complaintcasedata.ownerid + ")";

    with line

    jsondata["ownerid@odata.bind"] = "/teams(" + ((team)complaintcasedata.ownerid).teamid + ")";

    ownerid property is not string - it's an object of team type.

  • MohammadBB Profile Picture
    MohammadBB 325 on at
    RE: Unable to Update Ownerid field of custom entity using odata Json call

    The same thing for team would be like this:

    entity["ownerid@odata.bind"] = "/teams(" + teamId + ")"

  • Suggested answer
    RE: Unable to Update Ownerid field of custom entity using odata Json call

    After further investigation and digging through the full $metdata information of the API, the PATCH binding code from javascript should look like this :

    entity = { "ownerid@odata.bind" : "/systemusers(" + userId + ")" }

    I was trying everything but within the $metadata information for my custom entity, look to the "Partner" property, that's the name you should be using as the field name to bind to.  

  • RE: Unable to Update Ownerid field of custom entity using odata Json call

    Was there ever a solution found for this problem?  I'm running into the same issue trying to update the Owner of a custom entity record.  

  • RE: Unable to Update Ownerid field of custom entity using odata Json call

    but this line of code did not update ownerid,gives error bad Request, for other fields it works fine.

  • RE: Unable to Update Ownerid field of custom entity using odata Json call

    Hi,I'm using below json call to update OwnerId field.where ownerId is of type Team

    complaintCase.ownerid = new team { name = "Customer Relations", teamid = Guid.Parse("9072B3AE-F0CB-E511-810D-3863BB347D90") };

    jsondata["_ownerid_value@odata.bind"] = "/teams(" + complaintcasedata.ownerid + ")";

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: Unable to Update Ownerid field of custom entity using odata Json call

    Hi Shweta,

    Solution for the error bad request is discussed in the following thread.

    community.dynamics.com/.../149096

    Also, please refer the code in the following blog to update the owner lookup field.

    guruprasadcrm.blogspot.in/.../update-optionset-lookup-data-using.html

  • RE: Unable to Update Ownerid field of custom entity using odata Json call

    while updating ownerid am getting "Bad request" error

  • RE: Unable to Update Ownerid field of custom entity using odata Json call

    HI, thanks for reply, I changed my PATCH call,and tried to update other field with the PATCH call, and this field get updated properly, but I'm unable to update ownerid.

    My Patch call is as below, it works properly for other field but not for Ownerid:

    public async Task<string> Update(JObject entityTobeUpdated, Guid recordid, string clientURL)

           {

               var recordId = recordid.ToString();

               try

               {

                   //Create HttpClient object to send and receive Http Requests and Response

                   var httpClient = await _connectionManager.CreateHttpClient();

                   using (httpClient)

                   {

                       var jsonData = JsonConvert.SerializeObject(entityTobeUpdated);

                       HttpRequestMessage request = new HttpRequestMessage(new HttpMethod("PATCH"), new Uri(httpClient.BaseAddress + clientURL+"("+recordId+")")) { Content = new StringContent(jsonData, System.Text.Encoding.UTF8, "application/json") };

                       var response = await httpClient.SendAsync(request);

                       //If the response is Successfully executed then it will return the value true

                       if (response.IsSuccessStatusCode)

                       {

                           var recordUrl = response.Headers.GetValues("OData-EntityId").FirstOrDefault();

                           var splitRetrievedData = recordUrl.Split('[', '(', ')', ']');

                           recordId = splitRetrievedData[1];

                       }

                   }

               }

               catch (Exception exception)

               {

                   throw new CustomODataException(exception.Message, exception);

               }

               return recordId;

           }

  • JohnAnonymous Profile Picture
    JohnAnonymous 5,241 on at
    RE: Unable to Update Ownerid field of custom entity using odata Json call

    I'm missing the url you create to do the patch request. The error seems to point to a mismatch of the URL and the method (PATCH).

    Maybe try postman or advanced rest client to test your call. Makes testing the api much easier.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans