- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2024 01:03 AM
Hello,
I have been trying to create a GlideRecord request to a data set in a script action. But I cant call the values of different fields in the data set through dot walking, even though I can call the sys id of the data set.
And when I run the code as a Background script it works just fine... Any idea why it doesnt work as a script action? Thanks!
My Code:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2024 02:23 AM
On this table of yours - do you have any query business rule running ?
Maybe try:
var request_id = event.parm2 //this is the sys_id I want to call
var data_set = new GlideRecord("table_name");
data_set.setWorkflow(false); //Disables query business rules that could prevent the user from seing the record
if (data_set.get(request_id)) {
gs.info("test Number: " + data_set.getValue("number"));
// Get Value function returns "null". (Not if I run this exact code as Background Script)
} else {
gs.info("Record not found");
}
I dont know if the table is in global scope, scoped app, or something similar (domain separation) that could also cause issues.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2024 02:23 AM
On this table of yours - do you have any query business rule running ?
Maybe try:
var request_id = event.parm2 //this is the sys_id I want to call
var data_set = new GlideRecord("table_name");
data_set.setWorkflow(false); //Disables query business rules that could prevent the user from seing the record
if (data_set.get(request_id)) {
gs.info("test Number: " + data_set.getValue("number"));
// Get Value function returns "null". (Not if I run this exact code as Background Script)
} else {
gs.info("Record not found");
}
I dont know if the table is in global scope, scoped app, or something similar (domain separation) that could also cause issues.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2024 02:43 AM
Thanks a lot, that solved the problem! :))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2024 02:47 AM - edited ‎08-29-2024 02:48 AM
Please take into consideration that if you need to update the record in the script its VERY important that you do
data_set.setWorkflow(true) before data_set.update() so that BRs runs
var request_id = event.parm2 //this is the sys_id I want to call
var data_set = new GlideRecord("table_name");
data_set.setWorkflow(false); //Disables query business rules that could prevent the user from seing the record
if (data_set.get(request_id)) {
gs.info("test Number: " + data_set.getValue("number"));
// Get Value function returns "null". (Not if I run this exact code as Background Script)
data_set.setWorkflow(true)
data_set.setValue(xxxxxx);
data_set.update();
} else {
gs.info("Record not found");
}
Because setWorkflow(false) will also prevent Business rules from running on updates which can cause huge issues - work_notes, comments etc not working - other rules doesnt apply and so on!
I would probably look into the Query Business rule and adjust that so system is not hit by it - only apply the Query BR if users got role x of y.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2024 01:34 AM
Hi @onatdeviren
Try the below code :-
var request_id = event.parm2; // this is the sys_id you want to call
var data_set = new GlideRecord("table_name");
if (data_set.get(request_id)) {
gs.info("test Number: " + data_set.getValue("number"));
} else {
gs.info("Record not found");
}
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2024 02:03 AM
This didnt work. What I get is "Record not found". And again in the Background - Script record is found and printed correctly.