- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2024 08:24 PM
In my BR, I've the following lines
(function executeRule(current, previous /*null when async*/ ) {
// report DataCore
var table = current.getTableName();
var recSysId = current.sys_id;
var eventName;
var finalPayload = {};
var payload = new global.Foo().bar(table, recSysId);
var requestPayload = new global.JSON().decode(payload);
finalPayload.table = table.toString();
if (current.operation() == 'insert') {
finalPayload.operation = 'create';
} else {
finalPayload.operation = current.operation().toString();
}
finalPayload.data = requestPayload;
var sysHeader = gs.getProperty('gh.datacore.headervalues').split(',');
and the log says the following:
com.glide.script.RhinoEcmaError: Cannot convert null to an object.
sys_script.b8a9bfbb1b4de950c5722137b04bcb14.script : Line(16) column(0)
13: if (current.operation() == 'insert') {
14: finalPayload.operation = 'create';
15: } else {
==> 16: finalPayload.operation = current.operation().toString();
17: }
18: finalPayload.data = requestPayload;
19: var sysHeader = gs.getProperty('gh.datacore.headervalues').split(',');
Now what has stumped me are the following:
1. finalPayload is already defined as object on line 9
2. current.operation() is out of the box method
So what is causing the issue on line 16?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2024 11:13 PM
It appears that having multiple BRs with the same order will cause the current.operation() to sometimes be null. I changed the order to lower value and it solved the problem. But the cause is still unknown as to why does it behave that way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2024 08:42 PM
Hello @Nisar3 ,
Could you please log what current.operation returns in your case.
I would suggest to add logs for Payload and requestPayload variable as well.
So that we can get what values they have.
Thanks,
Valmik Patil
Thanks,
Valmik Patil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2024 08:50 PM
The error is from Prod, so difficult to add statements there directly. I haven't had luck reproducing it in dev instances.
But still, I don't see a need to print those as current.operation is ServiceNow method and not custom, so it's expected to have a value always and secondly the line error says line 16 so Payload and requestPayload variables are out of scope, right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2024 08:55 PM
Hi @Nisar3
apply below code.
if(current.operation != null)
finalPayload.operation = current.operation().toString();
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2024 08:59 PM
Interesting. Do you see any case where the out of the box method will be null?