- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 01:32 PM
Hi folks,
I am setting the scratchpad variables for a workflow and am using an encoded query. The query works fine when I run it in the .list view of my table and I get back a number of distinct records. When I use it in my script, however, it returns the same value for each row in my results. I tried using a for loop but that did not return anything. I am pretty sure the issue is with my 'while' statement but I don't know how to fix. Here is the code I am using, if anyone can see what the problem might be.
var user = current.variable_pool.user;
var justification = current.variable_pool.justification;
// Set scratchpad variables
var grUser = new GlideRecord('sys_user');
if (grUser.get(user)) {
var UserSite = grUser.u_adsitecode;
workflow.scratchpad.UserSite = UserSite;
workflow.scratchpad.UserName = grUser.u_samaccountname;
}
//Query for the HOT's
var strQuery = 'titleLIKEDir^titleLIKETechnology^active=true^u_adsitecode=' + UserSite + '^NQtitleLIKEHead^titleLIKETechnology^active=true^u_adsitecode=' + UserSite;
var HOTs = [];
var grHOTs = new GlideRecord('sys_user');
grHOTs.addEncodedQuery(strQuery);
grHOTs.query();
while (grHOTs.next()) {
HOTs.push(grHOTs.u_samaccountname);
}
workflow.scratchpad.Justification = justification;
workflow.scratchpad.UserHots = HOTs.join(',');
Thanks in advance, as always. Any help is most appreciated.
Best regards,
Ken
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 01:40 PM
Hi, I suspect the issue is that when you push a value into an array from a while loop, you need to push the value as a string. Otherwise the first value in the result set is returned over and over.
There was a technical explanation for this floating about somewhere (I think on stackhub) - something to do with the glidequery result being a pointer to an object.
Anyway try
while (grHOTs.next()) {
HOTs.push(grHOTs.u_samaccountname.toString());
}
If this isn't your issue, you may need to clarify/provide specific example so that the comminuty can better understand the configuration and cause.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 01:40 PM
Hi, I suspect the issue is that when you push a value into an array from a while loop, you need to push the value as a string. Otherwise the first value in the result set is returned over and over.
There was a technical explanation for this floating about somewhere (I think on stackhub) - something to do with the glidequery result being a pointer to an object.
Anyway try
while (grHOTs.next()) {
HOTs.push(grHOTs.u_samaccountname.toString());
}
If this isn't your issue, you may need to clarify/provide specific example so that the comminuty can better understand the configuration and cause.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 01:47 PM
Tony,
Thank you so much! That did the trick. Much appreciated!
Best regards,
Ken