
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2016 09:01 AM
Hi all
List collector results comparison question,
I'm looking to try to do a comparison of the first 7 letters of a user's record location field, ex abc1234
and then compare it to a list collector that the user has selected to see if any contain the same data. for example:
user1 is from usajersey -
(it's a string so the query needs to stop before the - example: usajersey - somecity)
they select from list collector a name like usaflorida - share \write. This is the friendly name , not the actual name that i'm using for comparision.
but I only need the first characters before the -, on both the list collector and the user to be compared.
(not quite sure how to trim it down to look before. I tried doing the search '-' with no luck. Any thoughts? I'll give my psuedo coding example.
var userloc = current.variables.requested_for.location;
userloctrim = trimmed value;
//I'm wanting to search the entire selected list for matches
if (current.variables.listcollector.toString().indexOf('userloctrim') > -1) {
workflow.scratchpad.match = 'true'
}
else
workflow.scratchpad.match = 'false'
So if it can't find the trimmed data from the user location it returns a false.
Any idea on how to approach this? Let me know if additional clarification is needed.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2016 10:29 AM
Derek,
you will have to query 'sys_user_group' table for this. Dot walking will not work. here is the script for that
var gr1= new GlideRecord('sys_user_group');
gr1.addQuery('sys_id','IN',current.variables.groups.toString());
gr1.query();
while(gr1.next()){
if(gr1.description.indexOf(locationName)==0){
workflow.scratchpad.match = 'true';
}
}
Thanks,
Abhinay
PS: Hit like, Helpful or Correct depending on the impact of the response

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2016 01:28 PM
If all 3 have the same starting part, it is ok, but if it finds that there are 2 of the same and one is different, it needs to return false.
So if all are A it's ok, but if it's 2 A and 1 B it needs to be false

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2016 01:37 PM
Derek,
Here is you updated script. Try this
workflow.scratchpad.match = false;
var displayName = "";
//get the part of location value before "-"
var loctest = current.variables.requested_for.location.getDisplayValue(); //works
var locationName = current.variables.requested_for.location.getDisplayValue().split("-")[0].trim(); //works
//get number of the selected locations from the list collector
var groups_number = current.variables.groups.split(",").length;
//check for each selected value from the list collector
var count=0;
var gr1= new GlideRecord('sys_user_group');
gr1.addQuery('sys_id','IN',current.variables.groups.toString());
gr1.query();
while(gr1.next()){
if(gr1.description.indexOf(locationName)==0){
count+=1;
}
}
if(count==groups_number){
workflow.scratchpad.match = true;
}
Thanks,
Abhinay
PS: Hit like, Helpful or Correct depending on the impact of the response

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2016 02:05 PM
Apparently what should be a match is pulling a false, IE should be true.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2016 02:10 PM
Looks like the group number is undefined.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2016 02:41 PM
Derek,
Just a minor tweak, This should work as expected now.
replace "var groups_number = current.variables.groups.split(",").length;" with "var groups_number = current.variables.groups.toString().split(",").length;"
Thanks,
Abhinay
PS: Hit like, Helpful or Correct depending on the impact of the response