- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 12:29 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 03:34 AM
Hello Aman,
we need to write async business rule,
because asset and CI are creating Simultaneously.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 12:34 AM
hello @Ak8977 ,
Please remove the occurrence's of current.update() in your script as in before BR there is no need to update your form .Also i have made few changes to your script please try with this one
current.short_description = current.location.name;
var gr = new GlideRecord('cmn_location');
gr.addQuery('sys_id',current.location);
gr.query();
if(gr.next()){
current.short_description = "inside if loop";
if(!gs.nil(gr.u_street.toString())){
current.street= gr.u_street.toString();
}
}
Hope this helps
Mark my answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 01:26 AM
hello Mohith,
I have same kind of scenarion, but this logic was not working over there.
I have created an asset, it automatically creates the CI. In that CI I need to set the short description as some serial number. In this case it was not working.
created the before business rule on CI table
var gr = new GlideRecord('alm_asset');
gr.addQuery('sys_id',current.asset);
gr.query();
if(gr.next()){
gr.short_description = "inside if loop";
if(!gs.nil(gr.serial_number.toString())){
current.short_description = gr.serial_number;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 01:37 AM
@Ak8977 is it before insert BR that you are trying to execute?
Also remove gr.short_description = "inside if loop"; line from the above code and try
if this works , Mark the appropriate answer as correct
THanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 02:06 AM - edited 08-17-2023 02:07 AM
I tried but it was not working.
yes it is a before insert business rule