Need to configure assignment rule using script?

Kruthik M Shiva
Tera Contributor

Hi All,
I have a requirement to configure assignment rule where if IT application owner is present ,then that user needs to be added to the group automatically which I have created. then that group should be selected as assignment group with assigned to field with the particular application owner. Can anyone please provide scripting to achieve this.
Thanks in advance

4 REPLIES 4

SumanthDosapati
Mega Sage
Mega Sage

Hi,

You can try below script

var gr = new GlideRecord('tablename');
gr.addEncodedQuery("give your encoded query here");
gr.query();
if (gr.next()) {
    current.setValue('assignment_group', gr.getValue('group_field_name'));
}

 

Mark as correct and helpful if it solved your query.

Regards,
Sumanth

Hi Sumanth,

In this script the user is not automatically adding to the group which I have created, can you please give the solution for complete requirement.
Thank you,

Hey Kruthik,

You can try this

//this will add user to group
var grmem = new GlideRecord('sys_user_grmember');
grmem.initialize();
grmem.group = "sysid of your group"; 
grmem.user = "sysid of the user to be added"; //if user is present in any field then you can use current.fieldname
grmem.insert();

//this below sample script will help you to set the assignment group and assigned to.
var gr = new GlideRecord('tablename');
gr.addEncodedQuery("give your encoded query here");
gr.query();
if (gr.next()) {
    current.setValue('assignment_group', gr.getValue('group_field_name'));
    current.setValue('assigned_to', grmem.user);
}
//make changes to script as per your requirement.

 

Mark as correct and helpful if it solved your query.

Regards,
Sumanth

 

@Kruthik M Shivaprasad 

 

Feel free to reach out if you have further questions or else you can mark an answer as correct and helpful to close the thread so that it benefits future visitors also.

Regards,
Sumanth