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

Async business rule does not get triggered (not using previous or current)

Senthil Saivam
Kilo Contributor

Hi,

I have a business rule that that is configured to run 'async', but this never gets triggered. If I just change it to run 'after' then it gets triggered. Below is the script (note that I am not using current or previous) and screenshots of how the business rule is configured.

I have used the script debugger with a breakpoint in the first line, but the breakpoint never gets hit when using 'async'.

Please let me know what I am missing.

cheers,

senthil

 

 (function executeRule(current, previous /*null when async*/) {

try {
var r = new sn_ws.RESTMessageV2();
r.setHttpMethod('POST');
r.setEndpoint('https://***');
r.setRequestBody(JSON.stringify({
action: sys_action,
table: sys_action_collection,
workflow: 'D4C27688-CF88-40DD-B90C-3ED91E8A23BB'
}));
r.setRequestHeader('Accept', 'application/json');
r.setRequestHeader('Content-Type', 'application/json');

var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
} catch (err) {
var message = err.message;
logError(message);
}

})(current, previous);

 

 

find_real_file.png

find_real_file.png

 

 

1 ACCEPTED SOLUTION

One possible cause could be the sys_action or sys_action_collection may not be available for async BRs. Try hard-coding those values and if it works, then those variables are the issue.

View solution in original post

8 REPLIES 8

Hi JC,

I am also getting the same error, "after" it is working but "async" is not trigerring. 

 

Can you please help me, with how to add this in BR script? Is there any syntax?

 

Thanks

Balaji

Senthil Saivam
Kilo Contributor

@JC Icaro thanks. You were right, hardcoding/removing sys_action and sys_action_collection fixed the problem.

Another related question, async BR's on delete action don't have access to current, right? If so, is there anyway to get the sys_id of the deleted record in an async BR? Or is changing the BR to 'after' the only way to get the sys_id of the deleted record?

cheers,

senthil

 

You should have access to current. Previous is the one which isn't available on async BRs.

Senthil Saivam
Kilo Contributor

current works for async BR's on create and update but not delete. So if I add 'sys_id: current.sys_id' to the script then it works for create and update but not delete. If this line is removed and there is no use of current then the async BR works for delete too.