List collector results comparison question

Derek10
Tera Expert

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.

1 ACCEPTED SOLUTION

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


View solution in original post

21 REPLIES 21

LaurentChicoine
Tera Guru

From my understanding, you're stucked with the trimming.



For doing your trimming you could use either regex: userloctrim = userloc.replace(/regex/, '')



Or



Use the split method to generate an array and then compare your values: userlocarray = userloc.split(' - ')



If you have a more precise example, let's say user imput + a list that you want to compare to, I could give you a real code.


Abhinay Erra
Giga Sage

Derek,



  Which table is the listcollector variable referencing? Is it location table? Because, when you say current.variables.listcollector- you will get the sys_id of all the records that are selected not the display value.



Thanks,


Abhinay



PS: Hit like, Helpful or Correct depending on the impact of the response


Hi Derek,



In addition to Abhinay's response, you could use getDisplayValue() to get the display values. Something similar to below should work for you.




workflow.scratchpad.match = false;


var displayName = "";


//get the part of location value before "-"


var locationName = current.requested_for.location.getDisplayValue().split("-").[0].trim();


//get all the selected locations from the list collector


var allSelected = current.variables.listcollector.getDisplayValue().split(",");



//check for each selected value from the list collector



for (var i=0;i<allSelected.length;i++) {


        displayName = allSelected[i].split("-")[0].trim(); //take the first part before - for each entry


        if (displayName.indexOf(locationName) != -1) {  


                  workflow.scratchpad.match = 'true'


        }


}





Hope that helps.


-Mandar


thank you gentlemen, let me take this and see what I can spin of it. I will hopefully have a update either today or Monday on this.   Hopefully between both of the assists I think I might be good.