UI Action Condition has long strings
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2017 11:34 AM
Hello.
A UI action has a condition in which current.u_stage is analyzed against a whole bunch of values. Due to the sheer number of conditions, it was determined that using current.u_stage == 'AAAA' || current.u_stage == 'BBBB' || current.u_stage == 'CCCC' etc wasn't going to cut it due to the character limit on the string field.
The idea that I had was to put the values in an array and use indexOf (current.u_stage) to search for it.
The condition string on the UI Action thus looks like as follows:
(['AAAA', 'BBBB', 'CCCC', 'DDDD', 'EEEE', 'FFFF', 'GGGG', 'HHHH'].indexOf (current.u_stage) > -1)
It doesn't seem to work however. Is there any way to use such a condition (checking to see if a value is in a list of values) to leverage if a UI action is displayed or not? A Script include was considered, but due to my company's restriction on putting in script includes, would prefer solely dealing with this in the Condition field alone.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2017 01:20 PM
what i would do instead is create a script include... for example testOfRecord()
in that script include you can put however large a condition you want to get it to resolveand have it work for you.. so build a script that will return the condition as a string.. and call the script include returning what the final string should be.. this will allow you to create as long a condition as you need.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2017 01:25 PM
Again, as I stated earlier, I want to avoid using Script Includes due to the immense amount of paperwork that I have to submit to the CAB to get this approved (Script Includes falls into the line of "Major Fixes" which require the full CAB process to continue). Two weeks of work for a one line fix.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2017 01:30 PM
sorry i missed that line.. you have the syntax for an array index of wrong...
http://wiki.servicenow.com/index.php?title=ArrayUtil#gsc.tab=0
you CAN define vars etc in a condition but you may run into a character limit issue again since you are going to have to define a variable as a new array util...
i have never TRIED it... but you MIGHT try adding a .toString() before the .indexOf and see if that works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2017 01:44 PM
Interesting.
Earlier I was advised that the ArrayUtil was being deprecated and that I would use the following:
var a = ['AAAA', 'BBBB', 'CCCC'];
var b = 'BBBB';
var c = 'DDDD';
if (a.indexOf(b) > -1)
return 'Inside Array';
if (a.indexOf (c) < 0)
return 'Outside Array';
I tested this code originally and it does appear to work. To be sure, I replicated the code I was doing onto a test instance and created a similar Script Include with a gs.print of the indexOf result only to find that it is coming back as 'undefined'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2017 02:51 PM
Raymond, your suggestion to use toString did actually help. Ended up doing something like this:
(('AAAA, BBBB, CCCC, DDDD, EEEE, FFFF, GGGG, HHHH').indexOf (current.u_stage) > -1)
in which instead of an array, it is now a string.
That appeared to have worked like a charm. Thanks.
Turns out that the Array Approach does work for script includes, but not useful in conditions. I forgot that I used a split on a string previously. That array works in the include.