Set Assignment Group by Client Script

masoud
Tera Contributor

I want to auto-assign the cases to the Assignment Group (A) based on the HR Service(B). I created below onLoad client script but it doesn't work:

function onLoad() {
var st = g_form.getValue('hr_service');
if(st == 'B'){
g_form.setValue('assignment_group','A');
}
}

 

Thank you

1 ACCEPTED SOLUTION

Willem
Giga Sage

What do you mean with 'it doesn't work'? What is the expected result? And what is happening when you run above script?

 

Things to check:

  • Any other scripts setting the assignment group on load?
  • Is there a reference qualifier on the assignment group field?
  • Is the value of hr_service really B?

To check please share following alert results:

function onLoad() {
    var st = g_form.getValue('hr_service');
    alert('alert 1 result=' + st);
    if (st == 'B') {
        alert('alert 2 result=' + g_form.getValue('assignment_group'));
        g_form.setValue('assignment_group', 'A');
        alert('alert 3 result=' + g_form.getValue('assignment_group'));
    }
}

View solution in original post

9 REPLIES 9

Pradeep Sharma
ServiceNow Employee

Hi Masoud,

 

Try 

function onLoad() {
var st = g_form.getValue('hr_service');
if(st == 'B' || st == 'b'){
g_form.setValue('assignment_group','PASS SYSID OF ASSIGNMENT GROUP A HERE');
}
}

I tried with sys id but it didn't work!

Can you put an alert i.e alert('in'); after if loop and confirm if the loop is working?

Yes, the loop is working! 

function onLoad() {
var st = g_form.getValue('hr_service');
if(st == 'B' || st == 'b' ){
g_form.setValue('assignment_group','77ee8edbe71....');
}

alert('in');
}