
- 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 11:29 AM
current.u_business_class.indexOf('sys_id_of_data_privacy_record') > -1