Need script to create alert when changing assignment group

Gary Snyder1
Tera Contributor

Having some issues creating a script that creates a pop-up when the assignment group changes from "Helpdesk" to "Messaging".

Currently, I can get the alert to appear whenever a ticket is opened (regardless of the current assignment group, or what it's changed to), or no alert at all.

I've gone through various "drafts" of a script, and the current one I have gives me an error that I can't use "current.assignment_group" in a client script.

Below is the code I have now where I get the error about the "current" use.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var GroupOld = previous.assignment_group;
    var GroupNew = current.assignment_group;

    if ((GroupOld == "Helpdesk") && (GroupNew == "Messaging")) {
        alert('Notify London');


    }
}

I can't seem to figure out how to properly use the "g_form(GetValue)" option.  Can someone point me in the right direction, or provide a code that will work for what I'm trying to do?

Thanks in advance!

 

3 REPLIES 3

Mohith Devatte
Tera Sage
Tera Sage

Hello , 

Instead of current and previous object please use g_form object.

Curent and previous  -- > Used in server side

g_form-->used in client side

var new = g_form.getValue('assignment_group'); //to get the new value

var old  = oldValue;

just replace these lines and try 

please accept this solution if this helps you 

AnirudhKumar
Mega Sage
Mega Sage

Hello Gary,

 

Actually this problem is deeper than this.

g_form.getValue('assignment_group') is only going to give you the new value and only the sysid of the group selected.

 

We could directly use sysid comparisons as shown below, but its not a good way.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

  

    if ((oldValue == "<<sysid of Helpdesk group>>") && (newValue == "<<sysid of Messaging group>>")) {
        alert('Notify London');


    }
}

 

As the above code involves directly using sysid , its not best practice.

I suggest you write a glideajax , pass the old value (sysid) and new value(sysid) to script include, find the names of the groups and then throw alert on the client script.

How would I write a glideajax to change the sysid to a name?