Assignment group autopopulate based on use's email

Swati k1
Tera Contributor

Hi All,

 

I have one requirement to auto populate group name based on user's email but below not working , tried so many ways but could not achieve please help

NOTE: Atul please dont reply on my question your always giving irrelevant reply diluted  question plz dont do

 

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

var caller = g_form.getReference('requested_for', doAlert);
}

function doAlert(caller) {


var email = g_form.setValue('email', caller.email);
var email1 = g_form.getValue('email');
var email2 = email1.toString().includes('@brillio.com');
alert("sgsg" + email1);
alert("sjsj" + email2);
if (email2) {
g_form.setValue('assignment_group', '1519fcdadbe2830027f17db33c961949', 'Helpdesk Team');
alert(assignment_group);
} else {

// g_form.setValue('assignment_group', '214d4cd68718c210f505cbb5cebb359a', 'IMG Helpdesk Team');
g_form.setValue('assignment_group.sys_id', '214d4cd68718c210f505cbb5cebb359a');
alert(assignment_group);
}

}

1 ACCEPTED SOLUTION

Madhan somesh
Mega Guru

Please replace your code with the below code. It is working fine for me. I just replaced few commands.

 

Also I noticed that you've removed the isLoading line in your code & because of it the script will execute onLoad & onChange as well(In my code I added that condition as well). 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue === '') {  //If you want your code to execute on Load as well you can comment if condition.
      return;   
   }
var caller = g_form.getReference('caller_id', doAlert);
}

function doAlert(caller) {


var email = g_form.setValue('description', caller.email);
var email1 = g_form.getValue('description');  //replace description with your variable i.e email
var email2 = email1.toString().includes('@example.com');
alert("sgsg" + email1);
alert("sjsj" + email2);
if (email2) {
g_form.setValue('assignment_group', 'b85d44954a3623120004689b2d5dd60a', 'CAB Approval');
alert(assignment_group);
} else {

// g_form.setValue('assignment_group', '214d4cd68718c210f505cbb5cebb359a', 'IMG Helpdesk Team');
g_form.setValue('assignment_group', '477a05d153013010b846ddeeff7b1225');
alert(assignment_group);
}

}

  

Please mark it as "Accept as Solution" and " Helpful. if this solution helped you.


Thanks & Regards,
Madhan Somesh.

View solution in original post

6 REPLIES 6

Sumanth16
Kilo Patron

Hi @Swati k1 ,

 

Create script Include and On-Change Client script.

Please refer to below thread

 

https://www.servicenow.com/community/itsm-forum/auto-populate-name-based-on-email-selected/m-p/23517...

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

James Chun
Kilo Patron

Hi @Swati k1,

 

Can you try changing your code to something below:

if (email2) {
g_form.setValue('assignment_group', '1519fcdadbe2830027f17db33c961949');
} else {
g_form.setValue('assignment_group', '214d4cd68718c210f505cbb5cebb359a');
}

If it still doesn't work, can you elaborate on what 'alert' you are getting?

 

Thanks

 

Andrew_TND
Mega Sage
Mega Sage

Hi, instead of adding to your technical debt can you not leverage the auto assignment rules? 

Auto Assignment documentation 

 

Please mark as helpful or if it’s resolved the issue, CORRECT! 

Alp Utku
Mega Sage

Which form are you working on? Incident, SCTASK etc?

I would suggest you to create Business Rule on the form (table) you work on.

You can achieve your requirement without coding.