After Business rule not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 01:45 AM
Hi developer,
I have created after business rule, but it dosen't work.
When I set this business rule to "before" it works.
I'm not sure why this happenes. Any suggestions?
Detail:
- When specific fields on "cmn_location" table are updated, populate that change info to "sn_grc_profile" table.
- There is annother Before Business rule which should be executed before this business rule. (update fields within cmn_location)
When: after, update
Script:
(function executeRule(current, previous /*null when async*/ ) {
var facilityId = current.sys_id;
var grFacilityEntity = new GlideRecord('sn_grc_profile');
grFacilityEntity.addQuery('cmn_location', facilityId);
grFacilityEntity.query();
while (grFacilityEntity.next()) {
grFacilityEntity.setValue('name', current.name);
grFacilityEntity.setValue('u_country', current.u_state.parent);
grFacilityEntity.setValue('u_business_area', current.u_business_area);
grFacilityEntity.setValue('u_department', current.u_business_area.u_department);
grFacilityEntity.setValue('u_company', current.u_business_area.company);
grFacilityEntity.update();
}
})(current, previous);
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 01:54 AM
@shun6 Can you try the following and see if it works.
(function executeRule(current, previous /*null when async*/ ) {
var facilityId = current.sys_id.toString();
var grFacilityEntity = new GlideRecord('sn_grc_profile');
grFacilityEntity.addQuery('cmn_location', facilityId);
grFacilityEntity.query();
while (grFacilityEntity.next()) {
grFacilityEntity.setValue('name', current.name.toString());
grFacilityEntity.setValue('u_country', current.u_state.parent.toString());
grFacilityEntity.setValue('u_business_area', current.u_business_area.toString());
grFacilityEntity.setValue('u_department', current.u_business_area.u_department.toString());
grFacilityEntity.setValue('u_company', current.u_business_area.company.toString());
grFacilityEntity.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 02:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 02:04 AM
Hi,
What is the condition of the BR? Script seems okay nothing standing out on why it runs before but not after.
Also is there any other script that runs on this transaction that might be cancelling further BRs? Like something that has setWorkflow(false)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 02:20 AM - edited 12-02-2024 02:21 AM
I'm not using condition.
There is a Before Business rule using "setAbortAction" for specific condition.
Though this if condition evaluate to false and following update actions have been done, After Business rule did't work.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('cmn_location');
gr.addQuery('u_name', current.u_name);
gr.addQuery('company', current.company);
gr.setLimit(1);
gr.query();
if (gr.next()) {
gs.addErrorMessage(gs.getMessage("Duplicate Error of Facility Name"));
current.setAbortAction(true);
}
var facilityName = current.u_name;
var companyCode = current.company.u_company_code;
current.name = companyCode + "_" + facilityName;
})(current, previous);