Script Action

onatdeviren
Tera Contributor

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: 

        var request_id = event.parm2 //this is the sys_id I want to call
        var data_set = new GlideRecord("table_name");
 
        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");
        }
1 ACCEPTED SOLUTION

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.

View solution in original post

12 REPLIES 12

Can you send the exact code you are using?

 

--------------------------------------------------------------------------------------------------------------------------


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/

I just changed the table name and the sys_id. But that's the exact code I have



var
request_id = 'insert_sys_id'; // I'm not allowed to share any kind of company info pls replace it with a sys_id

 

var data_set = new GlideRecord("my_table"); //again not allowed to name the table
if (data_set.get(request_id)) {
gs.info("Onat test Number: " + data_set.getDisplayValue());
} else {
gs.info("Onat test Record not found");
}

I actually had
data_set.getValue("number"); 

instead of getDisplayValue