- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
1) In the background script is working fine :
var taskSysId = '5f1f516dc35203d05a76d5fe0501315d';
var grTask = new GlideRecord('sc_task');
if (grTask.get(taskSysId)) {
var ritmSysId = grTask.request_item.toString();
gs.info("Found Parent RITM: " + ritmSysId);
var test = new x_custom_scope.CustomScriptInclude();
var variableJSON = test.getVariableJSON(ritmSysId);
gs.info("Variable JSON Output:\n" + JSON.stringify(variableJSON, null, 4));
} else {
gs.error("Could not find an sc_task record with the provided sys_id: " + taskSysId);
}
2) when i run via Business rules and script includes its getting the Sys_id Instead of script inlcude in the payload generation
...
var variableJSON = CustomScriptInclude.getVariableJSON(current.request_item.toString());
....
var payload = {};
...
payload.variables = variableJSON;
....
// Genericized custom table name
var transactionlogGr = new GlideRecord('x_custom_scope_transaction_log');
transactionlogGr.initialize();
transactionlogGr.payload = JSON.stringify(payload);
.......................
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
may you try replace
var variableJSON = vendorIntegrationOutboundUtils.getVariableJSON(current.request_item.toString());
to
var variableJSON = vendorIntegrationOutboundUtils.getVariableJSON(current.getValue('request_item'));
The issue occurs because in scoped Business Rules within ServiceNow, using current.request_item.toString() can fail to extract the pure string of the reference sys_id, passing a GlideElement object instead. This causes the GlideRecord query in the Script Include to fail or behave inconsistently.
The correct way to retrieve the sys_id as a clean string within the Business Rule context is to use current.getValue('request_item').
This helps other users find accurate and useful information more easily
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
what's your actual requirement?
share some screenshots etc
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
As is said When i run in background script i am able to get GetDisplay Value from the below line
jsonVariables.display_value = question.getDisplayValue();
But when actual scipt will run when created via sc_task i am getting the sys_id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Could you please try to replace this code in BR and try like this .
From :
var variableJSON = CustomScriptInclude.getVariableJSON(current.request_item.toString());
To:
var test = new x_custom_scope.CustomScriptInclude();
var variableJSON = test.getVariableJSON(current.request_item.toString()); //the way you did it in background script
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I tried this way as well but during the creation of payload this is getting impacted during the ccreation json format an html tags will come here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Sumanth,
This is a classic hurdle when generating integration payloads with Reference or Look Up Select Box variables. Because these variable types inherently store the sys_id as their underlying value in the database, server-side scripts will pull that sys_id by default unless explicitly instructed otherwise.
A few things to check in your implementation:
Display Value Extraction: Inside your getVariableJSON Script Include, ensure you are utilizing .getDisplayValue() rather than just grabbing the value. For example: gr.variables.your_variable_name.getDisplayValue();.
Instantiation Differences: I noticed a slight syntax discrepancy between your snippets. In the background script, you instantiate the Script Include with new x_custom_scope.CustomScriptInclude(). In the Business Rule, you are calling it statically via CustomScriptInclude.getVariableJSON(...). Ensure your Script Include is properly structured to handle static calls if you aren't instantiating it, and double-check your application scopes.
Variable Context: Sometimes Business Rules (especially if running asynchronously) handle the current.variables object differently than a GlideRecord query in a background script.
Updating your Script Include to explicitly map display values for lookup variables should resolve the payload discrepancy.