How to update assignment group based on department

Nitesh Chandana
Kilo Expert

Hello,

I had a table u_master, if i entered 'u_name' in u_master table,

Assignment group in another table named u_ticket should be updated based on the department of user(u_name) in u_master table.

If user belongs to IT department then the assignment group be changes to Software in U-ticket table.

my code is

(function executeRule(current, previous /*null when async*/) {

  // Add your code here

var gr= new GlideRecord('u_ticket');

gr.initialize();

gr.category=current.u_category;

  gr.u_short_description=current.u_short_description;

  //gr.u_caller_name=current.u_name;

        gr.u_caller_id=current.u_name.toString();

var target = new GlideRecord('sys_user');  

target.addQuery('department',current.u_bavk);  

target.query();  

if(target.next())  

{  

    //gs.info('found user '+target.sys_id);  

if(target.name.department == '8e7458c7db2132004dba5c00cf9619b2'){ // pass the sys_id of the Axis Department

  gr.u_assignment_group='2605925bdba532004dba5c00cf9619eb';   //Please pass the sys_id of the Axis rectify Group.

    gr.setReadOnly('u_assignment_group','true');

}

//gr.u_assignment_group = target.sys_id;  

}  

  gr.insert();

Can any one help me out??

Thanks.

Nitesh

1 ACCEPTED SOLUTION

Hi Nitesh,



The best way to implement this is via Business Rules. Please create an after Insert Business rule in u_master table with the below script. Please inactive all the existing Client Scripts which were created for this requirement and give it a try.




(function executeRule(current, previous /*null when async*/) {


      var name;


      var group;


      var user_name = current.u_name;


      var user = new GlideRecord('sys_user');


      user.addQuery('name', user);


      user.query();


      if(user.next()){


              name = user.sys_id;


              if(user.department == '8e7458c7db2132004dba5c00cf9619b2'){ //Sys_id of Axis Department


                      group = '2605925bdba532004dba5c00cf9619eb'; //Sys_id of Axis Group


              }


             


              var ticket = new GlideRecord('u_ticket');


              ticket.initialize();


              ticket.category = current.u_category;


              ticket.u_short_description = current.u_short_description;


              ticket.u_caller_id = name;


              ticket.u_assignment_group = group;


              ticket.insert();


              gs.addInfoMessage('New Ticket is created');


      }


      else{


              gs.addInfoMessage('New Ticket can not be created. Please provide valid User name');


      }


     


})(current, previous);




I hope this helps.Please mark correct/helpful based on impact


View solution in original post

6 REPLIES 6

Thanks for response Amlan


After trying too many ways. I didn't get desired output


Based on your questions, these are my clarifications.


Please free to ask any doubts you need.



1. yes, record should be created in u_ticket table when we submit in u_master


2.u_name in u_master table is string field and u_caller_id is reference field


3 yes u_assignment_group is referring to sys_user_group


4 yes, absolutely



Thanks


Nitesh.


Hi Nitesh,



The best way to implement this is via Business Rules. Please create an after Insert Business rule in u_master table with the below script. Please inactive all the existing Client Scripts which were created for this requirement and give it a try.




(function executeRule(current, previous /*null when async*/) {


      var name;


      var group;


      var user_name = current.u_name;


      var user = new GlideRecord('sys_user');


      user.addQuery('name', user);


      user.query();


      if(user.next()){


              name = user.sys_id;


              if(user.department == '8e7458c7db2132004dba5c00cf9619b2'){ //Sys_id of Axis Department


                      group = '2605925bdba532004dba5c00cf9619eb'; //Sys_id of Axis Group


              }


             


              var ticket = new GlideRecord('u_ticket');


              ticket.initialize();


              ticket.category = current.u_category;


              ticket.u_short_description = current.u_short_description;


              ticket.u_caller_id = name;


              ticket.u_assignment_group = group;


              ticket.insert();


              gs.addInfoMessage('New Ticket is created');


      }


      else{


              gs.addInfoMessage('New Ticket can not be created. Please provide valid User name');


      }


     


})(current, previous);




I hope this helps.Please mark correct/helpful based on impact