Issue when using inputs argument variable of type string in addQuery Action script step?

Brian Whyte
Kilo Guru

I've defined an action in flow designer to demonstrate a problem I'm seeing.  This action has two string inputs in the input block. One is named "hostname" and the other is named "group".  

 

I've defined script step with two input variables. One variable is named "mehost" and the other named "megroup" and both have the value of action->hostname and action->group respectively. I've written the code below and I am using the "Test" button in flow designer to test it.  When running the test, I enter a value of "systemx" for the hostname form input and "BOBSTEAM" for the group form input and then click "Run Test".

 

(function execute(inputs, outputs) {

var hostnameinput=inputs.mehost; //comes in with value systemx
var groupinput=inputs.megroup;  //comes in with value BOBSTEAM

//Query from sys_user_group table
var dyngroup="UG not Found";
var assignGrp2 = new GlideRecord('sys_user_group');
//assignGrp2.addQuery('name', '=', 'BOBSTEAM); //This query will return records
assignGrp2.addQuery('name', '=', groupinput ); //This query will NOT return records
assignGrp2.query();
while (assignGrp2.next()) {
dyngroup = assignGrp2.sys_id;
}
//Query from u_sys_accred
var dynorg="Org not Found";
var orggr2 = new GlideRecord('u_sys_accred');
//orggr2.addQuery('u_hostname', '=', 'systemx'); //When uncommented, this query will return records
orggr2.addQuery('u_hostname', '=', hostnameinput); //This query will NOT return records
orggr2.query();
while (orggr2.next()) {
dynorg = orggr2.u_asset_org;
}

outputs.groupsysid=dyngroup;
outputs.org=dynorg;
})(inputs, outputs);

 The problem is that when I test this, all of the outputs empty which to me indicates the queries didn't return any records.  However, if I change the addQuery lines to use static string values instead of the input string values passed to the script step, the outputs come back properly and are populated with content.  

 

I feel like there's a bug here.  It seems like I should be able to pass dynamic string input values into the script step for an Action and use then to do Glide Record lookups on those dynamic inputs to make business logic decisions.  This is on release  Quebec: Glide-quebec-12-09-2020__patch10-hotfix7b-07-26-2022.

1 ACCEPTED SOLUTION

Brian Whyte
Kilo Guru

Yikes, I think there may indeed be a bug here. On a whim, I did a replace on the string inputs to see if there were non-ascii characters there.  It seems there were. So, if you run into this same problem doing this on the inputs works to clean out whatever gunk is in there:

var hostnameinput = inputs.mehost.replace(/[^\x00-\x7F]/g, ""));
var groupinput= inputs.megroup.replace(/[^\x00-\x7F]/g, ""));

After this using them as arguments to .addQuery will work.

View solution in original post

1 REPLY 1

Brian Whyte
Kilo Guru

Yikes, I think there may indeed be a bug here. On a whim, I did a replace on the string inputs to see if there were non-ascii characters there.  It seems there were. So, if you run into this same problem doing this on the inputs works to clean out whatever gunk is in there:

var hostnameinput = inputs.mehost.replace(/[^\x00-\x7F]/g, ""));
var groupinput= inputs.megroup.replace(/[^\x00-\x7F]/g, ""));

After this using them as arguments to .addQuery will work.