
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2018 10:24 AM
I have an issue with scripting on a Submit UI Action button. Currently, the button checks for the existence of related records, for a particular event type, or if the user is submitting from mobile. If any of those is true, they can submit without adding a related record. If not, they get a message and are sent back to add a related record.
My problem is now I also have to check to see if there is a particular value added in a glide list. When I add the indexOf portion to the script, ALL submissions are allowed to proceed even when the particular value is not present. The addition is current.u_business_class.indexOf('Data Privacy') > -1 ... I've also tried != -1 but to no avail. Any ideas?
relatedRecordsIMCR();
function relatedRecordsIMCR () {
var relrec = new GlideRecord("u_risk_type");
relrec.addQuery('u_reference', current.sys_id);
relrec.query();
var num = relrec.getRowCount();
if (num > 0 || current.u_event_type == 'Heads-Up Alert' || current.u_business_class.indexOf('Data Privacy') > -1 || gs.isMobile() ) {
current.setValue('problem_state', 3);
current.update();
action.setRedirectURL('problem_list.do?sysparm_query=');
} else {
gs.addErrorMessage("Please provide at least one Asset Category and Risk Type before Submitting Report");
action.setRedirectURL(current);
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2018 11:26 AM
so your if statement would look like this in my scenario.
if (num > 0 || current.u_event_type == 'Heads-Up Alert' || bClassExists || gs.isMobile() ) {
...
}
And yes, you would pass in the sys_id of the Data Privacy option if it is a glide list referencing a table. if it is a glide list using a choice list, then pass in the choice value. to be sure, insert this log statement here and see what gets output in your system logs to make sure you understand what types of values you are working with.
var bClass = (current.getValue('u_business_class') || "").split(",");
gs.log(JSON.stringify(bClass));
var bClassExists = new global.ArrayUtil().contains(bClass, 'sys_id_of_business_class');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2018 10:35 AM
When you do current.u_business_class, this returns the backend values, comma separated. so you can use the sys_id if this is a reference glide list, or the choice value if it is a choice glide list. here is how I would update this passing in the sys_id or choice of the business class you want to check. then you can use bClassExists in your if statement.
var bClass = (current.getValue('u_business_class') || "").split(",");
var bClassExists = new global.ArrayUtil().contains(bClass, 'sys_id_of_business_class');
The reason I convert this to an Array is because it will find an exact match. For example if you just search "Data Privacy" using indexOf in a comma separated string of values, and there was another value called "Data Privacy 2", it would find a match there when it shouldn't.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2018 10:41 AM
So in your scenario, the line that contains the other validations would include this?
|| bClassExists.indexOf ('Data Privacy') > -1
There are only four choices in this list at the moment. If I go this route, would I put the sys ID in single quotes instead of the choice itself?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2018 11:26 AM
so your if statement would look like this in my scenario.
if (num > 0 || current.u_event_type == 'Heads-Up Alert' || bClassExists || gs.isMobile() ) {
...
}
And yes, you would pass in the sys_id of the Data Privacy option if it is a glide list referencing a table. if it is a glide list using a choice list, then pass in the choice value. to be sure, insert this log statement here and see what gets output in your system logs to make sure you understand what types of values you are working with.
var bClass = (current.getValue('u_business_class') || "").split(",");
gs.log(JSON.stringify(bClass));
var bClassExists = new global.ArrayUtil().contains(bClass, 'sys_id_of_business_class');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2018 01:30 PM
Thanks Jon ... this worked. I had to use u_involves (the field name on the form) vs u_business_class (the reference table holding the value), then the sysID for Data Privacy. Now to replicate in production! 😉