Async Business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2023 06:38 AM - edited 10-15-2023 10:56 PM
Hello All,
I need to copy tags using async business rule on the target table from source table is the associated reference field is having tag, it should be copied to the associated target record.
I am using below code-
written async BR on control test table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2023 07:31 AM - edited 10-15-2023 07:32 AM
Hi,
I don't have either the 'sn_compliance_internal_control_test' or the 'sn_compliance_policy_statement' table in my instance. And I'm not clear if either is the "target table" or the "source table". Nor have you specified which table the business rule is defined on. I have some comments on the code. see:
var gr = new GlideRecord("sn_compliance_internal_control_test");
// no query is present, what record is expected? As is done for 'label_entry' table below. I suspect no info message
// appears, and that won't work for an "async" business role. us "gs.info();" and check Script Log statements for
// results.
if (gr.getUniqueValue()) {
var contObId = current.u_control.content;
gs.addInfoMessage(contObId);
}
//label_entry with control object and get all the label entry for the control objective
var labels = new GlideRecord('label_entry');
labels.addEncodedQuery('table=sn_compliance_policy_statement^table_key=' + contObId);
labels.query();
// use of "if" here will only process one record, use "while" here to process all from the above query
if (labels.next()) {
gs.addInfoMessage(labels.label.getDisplayValue()); // use 'gs.info() here
var grLabelINCTask = new GlideRecord('label_entry');
grLabelINCTask.initialize();
grLabelINCTask.table_key = current.sys_id;
grLabelINCTask.table = current.sys_class.name;
grLabelINCTask.label = current.label;
grLabelINCTask.read = current.read;
grLabelINCTask.title = current.u_type;
grLabelINCTask.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2023 08:23 AM
Hello @Bert_c1 ,
Thank you for replying
I am talking about control test table.. please check the link below-
On this table, there is a reference field control.I have to copy tags to the control test record from the associated control objective, references from the control field via async business rule.
Let me know if you still have some queries
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2023 09:56 AM - edited 10-16-2023 04:21 PM
I suggest you change the When to After, and test you logic, addInfoMessage will work there.
which has:
addInfoMessage(Object message)
Use getInfoMessages() to retrieve the list of info messages being shown. This method is not supported for asynchronous business rules and cannot be used within transform scripts.
And for 'getUniqueValue' usage see:
There is no 'function' declaration in your code, should look like:
function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("sn_compliance_internal_control_test");
// no query is present, what record is expected? As is done for 'label_entry' table below. I suspect no info message
// appears, and that won't work for an "async" business role. use "gs.info();" and check Script Log statements for
// results.
// if (gr.getUniqueValue()) {
var contObId = current.u_control.content;
gs.addInfoMessage(contObId);
// }
//label_entry with control object and get all the label entry for the control objective
var labels = new GlideRecord('label_entry');
labels.addEncodedQuery('table=sn_compliance_policy_statement^table_key=' + contObId);
labels.query();
// use of "if" here will only process one record, use "while" here to process all from the above query
if (labels.next()) {
gs.addInfoMessage(labels.label.getDisplayValue()); // use 'gs.info() here
var grLabelINCTask = new GlideRecord('label_entry');
grLabelINCTask.initialize();
grLabelINCTask.table_key = current.sys_id;
grLabelINCTask.table = current.sys_class.name;
grLabelINCTask.label = current.label;
grLabelINCTask.read = current.read;
grLabelINCTask.title = current.u_type;
grLabelINCTask.insert();
}
}if 'u_control' is a reference field defined on that table the business rule is defined on.
