How to get Values from Custom with Label Variable ? How to set limit of values and restrict submit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2022 05:56 AM
There is a variable Custom with Lable for selecting multiple change requests. It should have at least 3 values before the submit form.
I have added script :
var Changes = g_form.getvalue("field_name").toString().split(',');
var changes_length = Changes.length;
if(changes_length>=3){
return true;
}
return false;
But this is always return false . How to achieve this can anyone please help ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2022 06:40 AM
@S Deva It should be return false; in the if block. Please check below code:
function onSubmit() {
var changes = g_form.getValue('<FIELD NAME HERE>');
changes = changes.toString().split(",");
if (changes.length >= 3) {
g_form.addErrorMessage("Action aborted.");
return false;
}
}
Please mark as correct answer if this solves your issue
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2022 06:57 AM
Its not working. Actually the length of the values is coming as "0" .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 06:02 AM
Hi @S Deva , Did you get any solution for this? i am also working on similar requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 05:28 AM
Hi @kiran Garide @S Deva Did you get the solution for this? I too have the same requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 05:42 AM
100% working solution.
You must validate that on in the widget (which is used in custom with label) it self. Create a new field (boolean) to store the validation result.
Use the new field in the on submit client script to abort the action.
Note:
On widget, to sent the value in new field use below syntax
$scope.page.g_form.setValue("<NEW FIELD HERE>", "<true/false validation result>");
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023