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

Simon Christens
Kilo Sage

Are you sure that event.parm2 actually contains what you expect ?
Try logging out the parm first to check.

I tried it yes, it gets the expected value. I also set the request_id manually to check if that s the problem. It's not the reason why it doesnt work

I just tested it and had no issues triggering an event from a Business rule (on record update) and then trigger a script action on that event - looking up the record from the sys_id and printing out the number.
If you log out data_set.getDisplayValue() what do you get then ?

I dont get anything back when I delete the if condition. I think there is a problem with the get function. I'm 100% sure the request_id has the correct value, because i just set the sys_id manually to that and got same results. With the current if condition I get "record not found" logged out.