Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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

Deepak Ingale1
Mega Sage

/* assumptions


  30 variables only


  All are true / false type


  Else, script will require changes


*/


var counter = 0;


var gr = new GlideRecord('sc_item_option_mtom');


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


gr.orderBy('sc_item_option.order'); // sort variables by ascending order


gr.query();


while(gr.next()){


    counter++;


    if(counter<=15){


  if(gr.sc_item_option.value == 'true') // please check this line, not sure what is stored as true whether 1 or string true


  callFirst(); // function defined in your run script to return 1st output


    }


    else if(counter> 15 && counter<=30){


    if(gr.sc_item_option.value == 'true'){


    callSecond(); // function defined in your run script to return 2nd output


    }


    }


    else callThird(); // function defined in your run script to return 3rd output


  }


}




Please check if it helps


That definately is helping, the other issue is, they are in 3 different areas in the order and not side by side. they are in sections. So I don't think i can use the counter. I have no problem delcaring out the vars if I must.



Any suggestions? (Btw what you have written I would not of figured out anytime soon)


Can you let us know a little more about what you are trying to accomplish and/or post a screenshot of your catalog item variables?


Sure,   this shows all the variables visually and my quandry. I am looking to find a way to say for example, if any of 1001 is checked in all 3 areas, it goes to 1 takes route a. (that is the simple version) the problem is, as you can see, alot more variables. so I'm looking to see how I can set this up without making a whole load of if statements and was looking at arrays with using the arrayutils to do a contain to check for a true. So if any of the listed vars. (for example 1001-1100) are checked it goes route A, if 4200-42009 are checked (any of them = true) then go route B, and then route C if there isn't any checked.   Both A and B can   both be checked so I am using a scratchpad marker as my conditional in code.


find_real_file.png