Mandatory comment on an incident state change

Luke James
Tera Contributor

Hello All,

 

I have a requirement to do the following on an Incident: 

 

I am mandated to update the Additional Comments field when:

  • I move an Incident into Cancelled state
  • I move an Incident from On hold into In Progress state for On hold reason Awaiting Caller
  • I move an Incident from Resolved to In Progress

I have setup a client script for this on change of state field. Below is my code: 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Check if moving to Cancelled state
if (newValue == 8) {
g_form.setMandatory('comments', true);
}
// Check if moving from On Hold to In Progress with On Hold reason Awaiting Caller
else if (oldValue == 3 && newValue == 2 && g_form.getValue('on_hold_reason') == 1) {
g_form.setMandatory('comments', true);
}
// Check if moving from Resolved to In Progress
else if (oldValue == 6 && newValue == 2) {
g_form.setMandatory('comments', true);
}
// Reset mandatory for other cases
else {
g_form.setMandatory('comments', false);
}
}

 

The problem I have is that when I change the value in the state field, it is not making the comments field mandatory on first change. It does on 2nd change, but not on the first. 

 

Anyone know how to make this work? 

 

Many Thanks, 

 

Luke

2 REPLIES 2

SanjivMeher
Kilo Patron
Kilo Patron

I would suggest using UI policy, which is much easier to manage.

Or try adding quotes while comparing and try below script

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
g_form.setMandatory('comments', false); // Keep comments non-mandatory initially
// Check if moving to Cancelled state
if (newValue == "8") {
g_form.setMandatory('comments', true);
}
// Check if moving from On Hold to In Progress with On Hold reason Awaiting Caller
else if (oldValue == "3" && newValue == "2" && g_form.getValue('on_hold_reason') == "1") {
g_form.setMandatory('comments', true);
}
// Check if moving from Resolved to In Progress
else if (oldValue == "6" && newValue == "2") {
g_form.setMandatory('comments', true);
}
}

 


Please mark this response as correct or helpful if it assisted you with your question.

I did think of this, but how would you manage an on change state in a UI policy?

 

Thanks for the comment, I will try the script :).