The CreatorCon Call for Content is officially open! Get started here.

business rule not working as expected

Ak8977
Tera Expert

In the sys_user table I have a street field. I am writing a before business rule when a new user was created and we select his location then the street field map with the street field in cmn_location table.
I have written the following business rule. But it was not working.

 

var gr = new GlideRecord('cmn_location');
gr.addQuery('sys_id',current.location);
gr.query();

current.short_description = current.location;
while(gr.next()){
current.short_description = "inside if loop";
if(!gs.nil(gr.u_street.toString())){
current.street= gr.u_street.toString();
current.update();
}
}
current.update();

 

It was not going to the if loop.

1 ACCEPTED SOLUTION

Hello Aman,
we need to write async business rule,
because asset and CI are creating Simultaneously.

View solution in original post

12 REPLIES 12

@Ak8977 

what's the current script and what's not working as expected?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Aman Kumar S
Kilo Patron

hi @Ak8977 ,

Refer to screenshot

asset.PNG

Best Regards
Aman Kumar

Hello Aman, if the serial number is empty then I need to fill it with asset tag, which is not possible from field values. so I go with script. The above script you shared also not workin, it was not entering  into the if loop if(gr.next()).