Warning message on creating P1 and P2 tickets

BowieC
Tera Contributor
I would like to create a warning message to avoid wrongly created P1 and P2 tickets.
I edited the OOTB client script as below and it works wonderfully on new ticket creation and accidental changing priority to P1 and P2.
However, the warning message also pops up when team is saving work on real P1 and P2 ticket.
How can I avoid that?
 
 
function onSubmit() {
    var priority = g_form.getValue('priority');
    if (priority <= 2)
        return confirm(getMessage('High priority ticket will notify global team. Do you confirm on submitting a high priority ticket?'));
}
 
1 ACCEPTED SOLUTION

You can use getControl(). The only thing, it doesn't work on Service Portal. So as long as you are not using portal, it should be fine.

function onSubmit() {
    var priority = g_form.getValue('priority');
    var priorityControl = g_form.getControl('priority');
    if (priority <= 2 && (g_form.isNewRecord() || priorityControl.changed))
        return confirm(getMessage('High priority ticket will notify global team. Do you confirm on submitting a high priority ticket?'));
}

 

The other option is as suggested by JP to use onChange, which will run when the priority is changed by user. The only thing is, user needs to save again after the popup.


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

View solution in original post

4 REPLIES 4

JP - Kyndryl
Kilo Sage

Hi Bowie,

If I understand well, you want to warn only if the priority changes to 1 or 2.

If so, I would rather go with a client script of type onChange:

 

JPKyndryl_0-1717714357832.png

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue === '' || g_form.isNewRecord())

        return;

    else if (newValue <= 2)

        return confirm(getMessage('High priority ticket will notify global team. Do you confirm on submitting a high priority ticket?'));

}

Regards,
JP

SanjivMeher
Kilo Patron
Kilo Patron

You can probably use another condition g_form.isNewRecord()

 

For ex. if (g_form.isNewRecord() && priority<=2)


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

Thank you, this is great.

However, it does not cover the scenario where engineer change an existing ticket to P2/P1.

I created a similar script using State to track it, but still does not completely cover the above scenario

You can use getControl(). The only thing, it doesn't work on Service Portal. So as long as you are not using portal, it should be fine.

function onSubmit() {
    var priority = g_form.getValue('priority');
    var priorityControl = g_form.getControl('priority');
    if (priority <= 2 && (g_form.isNewRecord() || priorityControl.changed))
        return confirm(getMessage('High priority ticket will notify global team. Do you confirm on submitting a high priority ticket?'));
}

 

The other option is as suggested by JP to use onChange, which will run when the priority is changed by user. The only thing is, user needs to save again after the popup.


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