1
0
-1

Hello community,

I have following payload from Jira SD:


"MoMe-Flag": {
"id": 11816,
"name": "MoMe-Flag",
"description": "for MoMe",
"type": "OPTIONS",
"value": [
{
        "id": "12399",
"sequence": 0,
"value": "Yes",
"disabled": false,
"childOptions": []
}
]
}


I have following incoming script on SN side:


if (replica.customFields."MoMe-Flag"?.value?.value == "Yes") {

incident.u_mome = true

} else {

incident.u_mome = false

}


but it doesn't set u_mome field = true from above payload. u_mome is boolean type field.

Hopefully, someone can help.

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      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.



      1. Andrew

        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.


      2. Francis Martens (Exalate)

        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
        
        



      3. Andrew

        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:


        1. mome true
        2. MoMe: [Yes]
        3. Flag1: [Yes]
        4. 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.

      4. Francis Martens (Exalate)

        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 ...

      5. Andrew

        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

      6. Francis Martens (Exalate)

        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.

      CommentAdd your comment...