Answer by Francis Martens (Exalate) on 16 March 2021
Are there any business rules around that field?
We have seen this in a number of cases where the business rule consequence is that ServiceNow silently ignores the update.
Comments:
Andrew commented on 16 March 2021
I did not find business rule around the field. incident.u_mome
is new custom field.
When I added below two lines to my script, I was able to update description field with sent binary value:
def mome = replica.customFields.âMoMe-Flagâ?.value?.value
incident.description = "MoMe: " + mome
and then description is MoMe: [Yes]
So I am able to display boolean value in text field, bt I cannot set with this value boolean field.
Francis Martens (Exalate) commented on 16 March 2021
Ah - replica.customFields.âMoMe-Flagâ?.value?.value is an array.
Can it be that it is a multi value field?
Following code takes into account that
- flag is null â false
- flag is empty â false
- flag has a value âtrueâ â true
It is untested ⌠but should work
Untested
def flag = replica.customFields."MoMe-Flag"?.value?.value
incident.u_mome = flag?.size ? (flag[0] == "true") : false
Andrew commented on 17 March 2021
Hello,
Positive payload is above, negative (or rather empty) payload from Jira is below:
"MoMe-Flag": {
"id": 11816,
"name": "MoMe-Flag",
"description": "for MoMe",
"type": "OPTIONS",
"value": [] },
I have added to incoming script with some âdiagnosticâ features as below:
def mome = replica.customFields."MoMe-Flag"?.value?.value.toString()
def flag1 = replica.customFields."MoMe-Flag"?.value?.value
def flag2 = flag1?.size ? (flag1[0] == "true") : false
if (mome == "[Yes]") {
incident.description = "1. mome true" + "\n" + "2. MoMe: " + mome + "\n" + "3. Flag1: " + flag1 + "\n" + "4. Flag2: " + flag2
incident.u_mome = flag1?.size ? (flag1[0] == "true") : false
} else {
incident.description = "a. mome false" + "\n" + "b. MoMe: " + mome + "\n" + "c. Flag1: " + flag1 + "\n" + "d. Flag2: " + flag2
incident.u_mome = flag1?.size ? (flag1[0] == "true") : false
}
So description field for positive payload looks as below:
- mome true
- MoMe: [Yes]
- Flag1: [Yes]
- Flag2: false
and for empty payload like here:
a. mome false
b. MoMe:
c. Flag1:
d. Flag2: false
So flag2 is always false and u_mome field is not updated to true.
Francis Martens (Exalate) commented on 18 March 2021
Check the logic.
flag2 will always be false because flag1 has the value âYesâ and not true. So the expression
flag1[0] == âtrueâ
Will always return false âŚ
Andrew commented on 22 March 2021
Yes, you are right Francis.
Iâve corrected script so now is:
def flag2 = flag1?.size ? (flag1[0] == "Yes") : false
and
incident.u_mome = flag1?.size ? (flag1[0] == "Yes") : false
so now flag2 = true
but incident.u_mome still is false
Francis Martens (Exalate) commented on 22 March 2021
Can you try without the expression
incident.u_mome = true
And see if this is accepted by ServiceNow. There might be a business rule ignoring the value.