If there is a way to modify the workflow wherein if the user is brazil then the request assign BAG

Srinivasu2
Tera Contributor

Hi Community,

 

If there is a way to modify the Existing workflow wherein if the user is Brazil then the request should land to Brazil Assignment group

 

Srinivasu2_1-1696233315553.png

 

 

Please check this above screenshot and advise how can we modify the above workflow?

 

Regards,

Srinivasu

 

8 REPLIES 8

Sorry, but i need to auto assignment group in RITM not Catalog task,

 

if user is Brazil, will auto assign to Brazil assignment group in RITM

if user is not Brazil, will flow continue to other activates in workflow

 

Hope you can the requirement, 

Could you please suggest workflow activities along with script that would be great full.

 

Thanking in advance

Hi @Srinivasu2 

 

You can use same logic in Run script activity 

 

 

/*1.Get the requested for*/
var reqFor  = current.requested_for;
var country;

/*2.glide record on sys_user table*/

var grUser = new GlideRecord("sys_user");
grUser.addQuery("sys_id", reqFor);
grUser.query();
if (grUser.next()) {
	
	country = grUser.location.country;
   
}

if(country == '<country_name here brazil>'){
	current.assignment_group = <sys_id of brazil group>;   //use system property to store sys_id. not to hardcode
      /*Set scratchpad variable will be used in "If script" activity to diver flow*/
      workflow.scratchpad.isBrazilUser = true;
  
} else {
	current.assignment_group = <sys_id of another group>; 
        /*Set scratchpad variable will be used in "If script" activity to diver flow*/
      workflow.scratchpad.isBrazilUser = false;
}

 

 

Use another "if" activity to divert the flow using scratchpad variable we set in above activity

 

  answer = ifScript();

  function ifScript() {
     if (workflow.scratchpad.isBrazilUser == true) {
        return 'yes';
     }
     return 'no';
  }

 

Hope this helps..!!

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Yes, I have used your code but it will always assign to "else group" not assign to "brasil group".

 

Srinivasu2_0-1696246043960.png

 

 

Srinivasu2_1-1696246119961.pngSrinivasu2_2-1696246208996.png

I couldn't find where did i do mistake, Could you please check and help me

 

Regards,

Srinivasu

 

Hi @Srinivasu2 

 

I can see there in user record you have country code field.

you can utilize that.

 

Check the backend value of choice Brazil from country code field & set it in run script

/*2.glide record on sys_user table*/

var grUser = new GlideRecord("sys_user");
grUser.addQuery("sys_id", reqFor);
grUser.query();
if (grUser.next()) {
	
	//country = grUser.location.country;
        country =grUser.<backend_value of country code field>
}

/*Check the backend value of Brazil from country code field*/
if(country == '<backend value of Brazil from country code field>'){
	current.assignment_group = <sys_id of brazil group>;   //use system property to store sys_id. not to hardcode
      /*Set scratchpad variable will be used in "If script" activity to diver flow*/
      workflow.scratchpad.isBrazilUser = true;
  
} else {
	current.assignment_group = <sys_id of another group>; 
        /*Set scratchpad variable will be used in "If script" activity to diver flow*/
      workflow.scratchpad.isBrazilUser = false;
}

 

                                                OR

 

get the sys_id of Brazil location from location table & set it

 

/*2.glide record on sys_user table*/

var grUser = new GlideRecord("sys_user");
grUser.addQuery("sys_id", reqFor);
grUser.query();
if (grUser.next()) {
	
	country = grUser.location;
        //country =grUser.<backend_value of country code field>
}

/*Compare the sys_id*/
if(country == '<sys_idd of brazil location>'){
	current.assignment_group = <sys_id of brazil group>;   //use system property to store sys_id. not to hardcode
      /*Set scratchpad variable will be used in "If script" activity to diver flow*/
      workflow.scratchpad.isBrazilUser = true;
  
} else {
	current.assignment_group = <sys_id of another group>; 
        /*Set scratchpad variable will be used in "If script" activity to diver flow*/
      workflow.scratchpad.isBrazilUser = false;
}

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates