2

I am using Microsoft Dynamics 365 and to access its database I am using Web API approach.

In here, I am having a field which is of lookup type and is having lookup values like below: Field information

In here, consider its code values as below:

Pending: 101
Booked : 102
...

And what I am passing as JSON data is:

{
    "statuscode":"101"
}

I have also tried like below:

"statuscode":101
"statuscode":"Booked"

But none of them is working for me. Can someone guide me on this?

EDIT 1: PUT Request

[ { "statuscode":101, "statecode":0 }, { "statuscode":101, "statecode":0 } ]

StringBuilder requestURL;
requestURL = new StringBuilder();
requestURL.Append(GenerateRequestURL(entityName));
requestURL.Append("(" + strGuID + ")");
HttpContent content = new StringContent(jsonFormattedData, Encoding.UTF8, "application/json");

Dictionary<string, string> returnValue;
HttpResponseMessage responseMessage;
returnValue = new Dictionary<string, string>();
try
{
    HttpClient httpClient = SetUpCRMConnection();
    HttpRequestMessage request;
    request = new HttpRequestMessage(httpMethod, requestUrl);
    request.Content = content;
    responseMessage = httpClient.SendAsync(request).Result;
    return GetFormattedResponse(responseMessage);
}
I Love Stackoverflow
  • 6,738
  • 20
  • 97
  • 216

1 Answers1

2

First of all, this is not lookup. This is picklist a.k.a optionset.

Then statecode (status/state) & statuscode (status reason) are conjoined twins. You have to set both at the same time & most important - they should be a valid combination.

For example:

This is for Account to set it inactive.

// State code value
account["statecode"] = 1;
//  status reason Value
account["statuscode"] = 2;

Similarly, you have this combination for your entity, put it together.

Something like this:

entity["statecode"] = 1; //check this for "Active" in Status dropdown
entity["statuscode"] = 101; //for pending
  • This is really helpful as I was totally unaware of this concept. And actually I have such 2 fields: - statecode - 0 / 1 - statuscode - 101/102/103 And I have tried with all possible combination for this but still getting 400 error. Can you tell me that how can I find that which fields are "Conjoined twins" in CRM database? OR Is there any option to check? – I Love Stackoverflow Jan 15 '18 at 05:24
  • @PratikSoni I guess you have 2 status code attributes. One is OOB statuscode 100000000 and other one custom new_statuscode 101. OOB attributes statecode & statuscode is mandate in same order. You can refer sdk/developer guide.. – Arun Vinoth-Precog Tech - MVP Jan 15 '18 at 11:27
  • not really. I have a single 'status code' only. Maybe my edited comment has confused you let me correct that again. – I Love Stackoverflow Jan 15 '18 at 11:41
  • 1
    @PratikSoni check the variable “strGuID” value, if it contains {} then remove it. Also why the jsonformatted data is having twice? – Arun Vinoth-Precog Tech - MVP Jan 16 '18 at 03:56
  • Oh! Thanks @ArunVinoth. Your point solved my issue. My code was expecting a single value of `status code` instead of list of it. Problem solved and thank you for your help. – I Love Stackoverflow Jan 16 '18 at 06:46