Unchanged string fields that were setSubmitMode('always') are sent to server side with empty string, and not null.
Steps to reproduce:
- Let's say we have two fields:
jk_nameof String type, andjk_dummyof any type. - Set
jk_namevalue tonull. Save the record. Call
setSubmitMode('always')on the String type field:Xrm.Page.getAttribute("jk_name").setSubmitMode("always");Change
jk_dummyvalue; don't changejk_namevalue.- Save the record.
Inside your plugin, watch your target's
Attributes, and you'll see:target -> Attributes -> Keys -> [0] -> "jk_name" target -> Attributes -> Values -> [0] -> ""meaning, the unchanged
jk_namefield is passed to the plugin with an empty string value.
Now, compare this to the case where you'd have another field, e.g., jk_code of Integer type. Repeat the steps above, and now you'd see:
target -> Attributes -> Keys -> [0] -> "jk_code"
target -> Attributes -> Values -> [0] -> null
meaning, the unchanged jk_code field is passed to the plugin with a null value.
To generalize:
Unchanged string fields that were setSubmitMode('always') are sent to server side with empty string, while unchanged non-string fields that were setSubmitMode('always') are sent to server side with a null.
Is there a specific reason CRM does that?
I wonder if this is a result of the primitives used by CRM. See here for a blog post from Guido Preite where he describes the different attribute types and default values
I've copied the main table here: