Onchange alert via client script

Viri
Tera Contributor

I wanted to pop up alert If the existing assignee is being removed from incident, show an alert
on form with some xyz message: how can I achieve it

1 ACCEPTED SOLUTION

Vishal Birajdar
Giga Sage

Hello @Viri 

 

You can write onChange client script on "Assigned to" field

 

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

    if (isLoading) {

        return;

    }

    if (newValue == '') {

        // for pop up

        alert("You have just removed Assignee...!!");

        // or you can show field ,essage as well

        g_form.showFieldMsg('assigned_to', "You have just removed Assignee...!!", "error");

    }  

}

 

Output : 

 

Alert Pop-up 

VishalBirajdar7_0-1694163640672.png

 

Field Message : 

 

VishalBirajdar7_1-1694163671174.png

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

2 REPLIES 2

Vishal Birajdar
Giga Sage

Hello @Viri 

 

You can write onChange client script on "Assigned to" field

 

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

    if (isLoading) {

        return;

    }

    if (newValue == '') {

        // for pop up

        alert("You have just removed Assignee...!!");

        // or you can show field ,essage as well

        g_form.showFieldMsg('assigned_to', "You have just removed Assignee...!!", "error");

    }  

}

 

Output : 

 

Alert Pop-up 

VishalBirajdar7_0-1694163640672.png

 

Field Message : 

 

VishalBirajdar7_1-1694163671174.png

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

msd93
Kilo Sage
Try using the below on change client script on incident table, where field name = Assigned to. I have given both the options of alert which is a pop up box (or) you may consider using field messages.
 
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading) {
        return;
    }

    if (newValue === '') {
        alert('Existing Assigned to user is removed');
        g_form.showFieldMsg('assigned_to''The "Assigned to" field cannot be empty.''error');
    }
}
 
Let me know if this works for you