Context: I have a custom field "customfield_10128" of type "Select" with the name "Status F1" and a custom field "customfield_10133" of type "DatePicker". I need the field "customfield_10133" to become a required field when the value of the field "Status F1" equals "Done".
To accomplish this, I use the ScriptRunner app and configured a behavior that triggers in the "Issue View" and the "On Load" and "On Change" events. This is the script I added to the behavior:
const statusF1 = getFieldById('customfield_10128').getValue().value
if(statusF1 == 'Done'){
getFieldById('customfield_10133').setRequired(true)
}else{
getFieldById('customfield_10133').setRequired(false)
}
When I open the issue to edit and modify the value of the "Status F1" field to "Done", the Chrome console shows me this result:
Time took to load the sandbox: 166087.30ms
index.js:1 Time took to call forge getFields() api: 0.30ms
index.js:1 Time took to run behaviour: 15.70ms
(4) [{…}, {…}, {…}, {…}]
[
{
"@timestamp": "2024-04-03T15:41:56.666Z",
"message": "Added new tracking event: {\"event\":\"Behaviours API call\",\"apiMethod\":\"getFieldById\",\"targetField\":\"customfield_10128\",\"count\":1,\"fieldId\":\"b99d0140-65e3-4416-9085-2db4dbea0124\",\"affectedField\":\"customfield_10133\"}",
"level": "info",
"uuid": "b99d0140-65e3-4416-9085-2db4dbea0124",
"fieldName": "customfield_10133",
"correlationId": "85566888-4315-4975-945c-a4878d5d1456",
"event": "ONCHANGE",
"view": "Issue view"
},
{
"@timestamp": "2024-04-03T15:41:56.667Z",
"message": "Added new tracking event: {\"event\":\"Behaviours API call\",\"apiMethod\":\"getValue\",\"targetField\":\"customfield_10128\",\"count\":1,\"fieldId\":\"b99d0140-65e3-4416-9085-2db4dbea0124\",\"affectedField\":\"customfield_10133\"}",
"level": "info",
"uuid": "b99d0140-65e3-4416-9085-2db4dbea0124",
"fieldName": "customfield_10133",
"correlationId": "85566888-4315-4975-945c-a4878d5d1456",
"event": "ONCHANGE",
"view": "Issue view"
},
{
"@timestamp": "2024-04-03T15:41:56.667Z",
"message": "Added new tracking event: {\"event\":\"Behaviours API call\",\"apiMethod\":\"getFieldById\",\"targetField\":\"customfield_10133\",\"count\":1,\"fieldId\":\"b99d0140-65e3-4416-9085-2db4dbea0124\",\"affectedField\":\"customfield_10133\"}",
"level": "info",
"uuid": "b99d0140-65e3-4416-9085-2db4dbea0124",
"fieldName": "customfield_10133",
"correlationId": "85566888-4315-4975-945c-a4878d5d1456",
"event": "ONCHANGE",
"view": "Issue view"
},
{
"@timestamp": "2024-04-03T15:41:56.667Z",
"message": "Added new tracking event: {\"event\":\"Behaviours API call\",\"apiMethod\":\"setRequired\",\"targetField\":\"customfield_10133\",\"count\":1,\"fieldId\":\"b99d0140-65e3-4416-9085-2db4dbea0124\",\"affectedField\":\"customfield_10133\"}",
"level": "info",
"uuid": "b99d0140-65e3-4416-9085-2db4dbea0124",
"fieldName": "customfield_10133",
"correlationId": "85566888-4315-4975-945c-a4878d5d1456",
"event": "ONCHANGE",
"view": "Issue view"
}
]
behaviours-sandbox.html:23
POST https://hydrogen.sagittarius.connect.product.adaptavist.com/behaviours/logs?jwt=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InBsME9oSHJucnJoQzFqcC1tNlluRSJ9.eyJjbG91ZFVybCI6Imh0dHBzOi8vbWF2aS1qanRvcnJlcy5hdGxhc3NpYW4ubmV0IiwiY2xpZW50S2V5IjoiNDAxNjNjMDItOGFmMy0zNTlhLTk0OGQtYjE2ZTIwZDZhNDNhIiwiaWF0IjoxNzEyMTU4NzUzLjI3NywiZXhwIjoxNzEyMjQ1MTUzLjI3NywiaXNzIjoic3ItYmVoYXZpb3Vycy10cmFja2luZyJ9.Dj27SDNKkuETkGQi0rw88DRgcbacFDuF6YF6AQtLjlY34x9dFAKuAZ6_JksnoAIyubLWzTIYofOAxw7VPb3OVSb9lLy0SnHZ-EvYiEQMiXkrwV7QmXMnB-u5qXVOKn2qqg5mxan7A7LDAmF-j02abJFzjfVBrAEuuqAimQou7nUD50PK7FNDCqp9xZLdg2mwzkGkoq45QjiO4tQ0r_0qQ2IqpWrmMgtiptrdNoDGPpy7jmKChQoWVyviU1ET3zTa0AI4rv6A7ZheW56nncFaZs_MGCcujELIcQIegTk7pkVhZjLiNUIO0ktfi3jmSdoQAjXM82GJ9xN4GGSb2vRFEg&correlationId=85566888-4315-4975-945c-a4878d5d1456 400 (Bad Request)
| | Wt | | behaviours-sandbox.html:23 |
| | Kt | | behaviours-sandbox.html:23 |
| | onChange | | behaviours-sandbox.html:33 |
| | await in onChange (async) | | |
| | (anonymous) | | behaviours-sandbox.html:23 |
| | c | | behaviours-sandbox.html:23 |
| | i | | behaviours-sandbox.html:23 |
When I add a value to the "customfield_10133" field and then remove it JIRA does not mark it as required.
I don't understand why my script doesn't work, please can someone help me.