-2

Is it possible to update a record's attribute of picklist type with null by using Sdk.Sync.Update? It's not working for me.

Here's what I do:

var detailsObj = updatedDetailsObj; // I get updatedDetailsObj from previous logic, not shown here
var operation = new Sdk.Entity("kcl_operation");
operation.setId(operationId, false); // I have operationId from previous logic, not shown here 
operation.addAttribute(new Sdk.String("op_updatedAccount", detailsObj.UpdatedAccount)); // works, get updated
operation.addAttribute(new Sdk.OptionSet("op_updatedExplanation", null)); // doesn't get updated
Sdk.Sync.update(operation);

After the completion of Sdk.Sync.update, the string field get updated, but the picklist field is left with its previous value, instead of null. I also took a look inside the XML being sent inside Sdk.Sync.update, and indeed, it lacks the pair of "op_updatedExplanation" and null.

How can make it work?

Added: I'm not doing it inside a form but inside a grid page, so that the user checks several records and I need to make the update on all of them.

OfirD
  • 9,442
  • 5
  • 47
  • 90
  • 3
    the methods you are calling are customs, they are wrappers to the real SDK messages, you should ask to who wrote that methods – Guido Preite Jun 15 '17 at 17:29
  • I don't mind not using them, I'll accept an answer that shows how can it be done in another way. – OfirD Jun 15 '17 at 17:35
  • As Guido mentioned, you are using a custom library, which most probably does not support setting option set values to `null` properly. With only the snippet you are showing we can not help you to fix this. – Henk van Boeijen Jun 15 '17 at 21:39
  • What else would you like to know? – OfirD Jun 15 '17 at 21:45

2 Answers2

0

standard CRM SDK code (assuming entity name and field name):

Entity operation = new Entity("kcl_operation");
operation.Id = operationId;
operation["op_updatedexplanation"] = null;
service.Update(operation);

where service is an IOrganizationService instance

Guido Preite
  • 14,905
  • 4
  • 36
  • 65
0

Please use this snippet to set value as null.

Xrm.Page.getAttribute("op_updatedexplanation").setValue(null);

This will just set the value in the form. You may have to save the form to see the value getting stored in database.

Xrm.Page.data.entity.save();

If the control is disabled - you have to set the submitmode attribute also.

Xrm.Page.getAttribute("op_updatedexplanation").setSubmitMode("always");
  • 1
    Sorry, I should have mentioned it: I'm not doing it inside a form but inside a grid page, so that the user checks several records and I make the update on all of them. – OfirD Jun 15 '17 at 19:24
  • You have to explore & use these options whichever you are comfortable - https://msdn.microsoft.com/en-us/library/gg309549(v=crm.7).aspx – Arun Vinoth-Precog Tech - MVP Jun 15 '17 at 19:45