Mapping assignment group basede on the lookup Table

Arun Priya
Tera Contributor

Hi, I need to give assignment group for a catalog item based on the Product choosed,  the product and the assignment groups are  provided in the lookup table. I have used the below script, but it is not working. can anyone help ?

 

Script: 

var assignment_group = '743cfdd39792bdd4cec4b9f0f053af2c';
var lookUp = new GlideRecord('u_bayer_catalog_appl_lookup');
lookUp.addQuery('u_catalog_item',current.cat_item);
lookUp.addQuery('u_application', current.variables.product);
lookUp.query();
if(lookUp.next()) {
current.assignment_group=lookUp.u_assignment_group;
}
else{
current.assignment_group = assignment_group;
}

3 REPLIES 3

Ravi Chandra_K
Kilo Patron
Kilo Patron

Hello @Arun Priya 

Try adding logs to see what values you are getting.

 

Also, I beleive it should be if(lookUp.hasNext()) to check if the record is present after query 

(You can also use while(lookUp.next()) ).

 

 

Please Mark this answer as helpful and correct if helped

Kind Regards,

Ravi Chandra 

Hi Ravi,

 

Will try and let you know

Harneet Sital
Mega Sage
Mega Sage

Hi @Arun Priya 

Widely the script looks correct and should work, try adding two more things to the script : 

1. if this is an after update business rule, add current.update() after the assignment group assignments and see if that works

2. Secondly try adding .sys_id in both your addquery and your attribute assignments. 

var assignment_group = '743cfdd39792bdd4cec4b9f0f053af2c';
var lookUp = new GlideRecord('u_bayer_catalog_appl_lookup');
lookUp.addQuery('u_catalog_item',current.cat_item.sys_id); //UPDATED
lookUp.addQuery('u_application', current.variables.product.sys_id); //UPDATED
lookUp.query();
if(lookUp.next()) {
current.assignment_group=lookUp.u_assignment_group.sys_id; //UPDATED
current.update(); //UPDATED
}
else{
current.assignment_group = assignment_group;
current.update(); //UPDATED
}

 
-Harneet Sital
Request you please mark my answer as helpful or correct based on the impact
Find all my ServiceNow articles here