state transition in problem form

Priya V M
Tera Contributor

When the state in problem form changes from new to any other state or from cancelled to any other state then work notes to be made mandatory. How to achieve this using UI policy as there is no changes option.

1 ACCEPTED SOLUTION

@Priya V M 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@Priya V M 

for this you need to use onChange and you will know the earlier value(present in database) and the current value

OR

you can use before update business rule

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    if (current.state == 'cancelled' && previous.state == 'new' && current.work_notes == '') {
        gs.addErrorMessage('Please fill work notes');
        current.setAbortAction(true);
    }

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar i have tried with on change client script it works only one way, it wont work the reverse way
can you suggest using client script or UI policy rather going to BR

@Priya V M 

you want work notes to be mandatory when

1) state changes from new to any

OR

2) state changes from Cancelled to any

try this and give correct state choice values

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    
    // Check if the state is changing from 'New' or 'Cancelled' to any other state
    if ((oldValue == '1' && newValue != '1') || (oldValue == '7' && newValue != '7')) {
        g_form.setMandatory('work_notes', true);
    } else {
        g_form.setMandatory('work_notes', false);
    }
}

Also you can use business rule approach as shared by me earlier

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Priya V M 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader