- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2015 09:02 AM
Hello all,
I am having an issue with my Get query array. I am attempting to add a security group to the variable workflow.scratchpad.group. Only one record must be set at a time due to me using this workflow.scratchpad.group variable for a powershell script.
My intent is to get all matching records in a array then parse it with a split separated by commas. With position, update workflow.scratchpad.group for the first record, then the second record and so on until there is no more records left. I have a checker to identify when there is no more records. which is not documented below.
Here is my code below.
Any help is appreciated Thanks.
workflow.scratchpad.dlPosition = 0;
getGroup(workflow.scratchpad.dlPosition);
function getGroup(position) {
var gr = new GlideRecord('u_user_role_privilege');
if(gr.get('u_location', workflow.scratchpad.locationOfGroup[position])){
workflow.scratchpad.group = gr.u_dn;
workflow.scratchpad.dlPosition++;
}
}
var groupArr = [];
var list;
var rolePrivilege = new GlideRecord('u_user_role_privilege');
rolePrivilege.addQuery('u_location',workflow.scratchpad.location);
rolePrivilege.query();
while(rolePrivilege.next())
{
groupArr.push(rolePrivilege.u_location.toString());
}
for(var count=0; count< groupArr.length; count++)
{
list = groupArr[count];
workflow.scrathpad.locationOfGroup = list.split(',');
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2015 11:56 AM
Edwin,
Thanks everyone for putting your minds together on this matter. I will show you what I believe is working now.
Determine array
var groupArr = [];
var list;
var rolePrivilege = new GlideRecord('u_user_role_privilege');
rolePrivilege.addQuery('u_location',workflow.scratchpad.location);
rolePrivilege.query();
while(rolePrivilege.next())
{
groupArr.push(rolePrivilege.u_ad_group.toString());
}
workflow.scratchpad.locationOfGroup = groupArr;
Get Query
getGroup(workflow.scratchpad.dlPosition);
function getGroup(position) {
var gr = new GlideRecord('u_user_role_privilege');
if(gr.get('u_ad_group', workflow.scratchpad.locationOfGroup[position])){
workflow.scratchpad.group = gr.u_dn;
workflow.scratchpad.dlPosition++;
}
}
ifScript Any more Records?
answer = ifScript();
function ifScript() {
if (workflow.scratchpad.locationOfGroup.length > workflow.scratchpad.dlPosition) {
return 'yes';
}
return 'no';
}
I also found a spelling error too which could have been another issue.
Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2015 11:56 AM
Edwin,
Thanks everyone for putting your minds together on this matter. I will show you what I believe is working now.
Determine array
var groupArr = [];
var list;
var rolePrivilege = new GlideRecord('u_user_role_privilege');
rolePrivilege.addQuery('u_location',workflow.scratchpad.location);
rolePrivilege.query();
while(rolePrivilege.next())
{
groupArr.push(rolePrivilege.u_ad_group.toString());
}
workflow.scratchpad.locationOfGroup = groupArr;
Get Query
getGroup(workflow.scratchpad.dlPosition);
function getGroup(position) {
var gr = new GlideRecord('u_user_role_privilege');
if(gr.get('u_ad_group', workflow.scratchpad.locationOfGroup[position])){
workflow.scratchpad.group = gr.u_dn;
workflow.scratchpad.dlPosition++;
}
}
ifScript Any more Records?
answer = ifScript();
function ifScript() {
if (workflow.scratchpad.locationOfGroup.length > workflow.scratchpad.dlPosition) {
return 'yes';
}
return 'no';
}
I also found a spelling error too which could have been another issue.
Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2015 11:57 AM
Looks good Travis! Glad it's working now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2015 11:05 AM
Is this your issue here:
for(var count=0; count< groupArr.length; count++)
{
list = groupArr[count];
workflow.scrathpad.locationOfGroup = list.split(',');
}
Do you need the for loop?
workflow.scrathpad.locationOfGroup = groupArr.split(',');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2015 11:21 AM
I think that would throw an error since array doesn't have a split method.
He can populate the scratch variable directly in the while loop I guess.