Array Question

Derek10
Tera Expert

I have a scenario, where I have 30 variables and 3 outcomes.

I'm trying to find the best way to make this as dynamic as possible. They are all check boxes. Basically I'll be looking at 1-15 if any are true, do this, 16-30   if any are true do that, if none are true, go here.

Doing a run script as a switch because multiple outcomes can happen concurrently.

I could use abit of help with the syntax. I looked up the arrayutil in the wiki which I think will help as it does the contains option. ArrayUtil - ServiceNow Wiki

But i'm not sure how to setup the array using vars and telling it to search through all 15 at a time. I'm assuming I manually have to enter them into the array.

Any thoughts out there? This is on the workflow side for clarity.

21 REPLIES 21

Okay, that helps me understand a little. If possible, could you also take a screenshot of the backend, ideally showing the variables order, question, and possibly value? If there is a privacy concern, then maybe just list a few examples from each section. In the meantime I will see if we have done anything similar.


I'll have to update that portion later on today. Thanks for the rapid feedback. There is some privacy concerns on the label names, but nothing I can't address.



There is around 183 variables in the form. I'll take the separate screenshots of the areas that are being addressed.


I would recommend trying to build a GlideRecord query that will search for the variables you want that have a value of true.   If the query returns any results then you know you have at least one box in that group checked.   If not, then you can do a query for variables in group 2 that have a value of true.   Let the database do the heavy lifting of trying to sort out which items are checked and then all you have to do is redirect your flow if it finds anything.



var gr = new GlideRecord('sc_item_option_mtom');  


gr.addQuery('request_item','current.sys_id');


gr.addQuery('sc_item_option.value',true);


gr.addQuery('sc_item_option.question','STARTSWITH','10');   // check this field name I'm not sure that is the right one


gr.query();


if(gr.next())


      //run whatever code you need for route A


else


          //create another query to search for the next group



You may have to get creative in creating your queries, but that may be the most efficient way to get what you need.   If there is some common naming scheme or grouping you can leverage that may help make your query simpler to write.  



-Steve


This may give me what I need, all I have to do is just name the var name with a certain ENDSWITH (or whatever the syntax is) and keeps it dynamic.   Thanks for the level of help. You have gone above and beyond.


I've started on this but apparantly the query isn't working quite up to pair, it's failing somewhere. I've changed your startswith to the endsWith() per some research. I'm not getting any feedback on the germ2 log but germ1 and 3 are consistent, which tells me beyond the missing log, it's nto changing.






var gr = new GlideRecord('sc_item_option_mtom');


workflow.scratchpad.germany = 'false';
gs.log('germ1 is   ' +workflow.scratchpad.germany);
gr.addQuery('request_item','current.sys_id');  
gr.addQuery('sc_item_option.value',true);  
gr.addQuery('sc_item_option.question','endsWith()','_germ');   // check this field name I'm not sure that is the right one  
gr.query();  
if(gr.next()){
      //run whatever code you need for route A  
workflow.scratchpad.germany = 'true';
gs.log('germ2 is   ' +workflow.scratchpad.germany);
}
gs.log('germ3 is   ' +workflow.scratchpad.germany);



p.s. How did you guys both it in that code format on the post?