scripts to check variable is empty or not
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 07:39 PM
I have create 2 variable as per below
variable A = multiline text
variable B - attachment
the above variable is not set as mandatory field and I would like to create a on submit scripts to check base on the below scenario
Scenario 1
Variable A = empty
Variable B = empty meaning no attachment
the script should alert with message when requester press order now button
Scenario 2
Variable A = not empty
Variable B = empty meaning no attachment
the script is not alert with message and requester can press order now button
Scenario 3
Variable A = empty
Variable B = not empty meaning got attachment inside
the script is not alert with message and requester can press order now button
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 10:35 PM
the scripts does not work as expected and it should follow below scenario
Variable A = not fill
Variable B = no attachment
the script should alert with message when requester press order now button
Scenario 2
Variable A = fill
Variable B = no attachment
the script is not alert with message and requester can press order now button
Scenario 3
Variable A = not fill
Variable B = with attachment
the script is not alert with message and requester can press order now button
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 10:41 PM
Try below script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 09:34 PM - edited 06-20-2023 10:13 PM
Hi,
Please try this script
Please mark my answer to correct or helpful if it works for you.
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 09:49 PM
thank you for the scripts but my scenario should works as per below.
Variable A = not fill
Variable B = no attachment
the script should alert with message when requester press order now button
Scenario 2
Variable A = fill
Variable B = no attachment
the script is not alert with message and requester can press order now button
Scenario 3
Variable A = not fill
Variable B = with attachment
the script is not alert with message and requester can press order now button
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 10:00 PM
HI @TMKAM ,
I trust you are doing great.
If Variable A is empty and Variable B is empty:
- Display an alert message to the requester when they press the "Order Now" button.
If Variable A is not empty and Variable B is empty:
- Do not display an alert message.
- Allow the requester to press the "Order Now" button.
If Variable A is empty and Variable B is not empty:
- Do not display an alert message.
- Allow the requester to press the "Order Now" button.
To implement this solution, you can create an on-submit script in ServiceNow. Here's an example of how the script might look like in Javascript:
(function() {
var variableA = g_form.getValue('variableA');
var variableB = g_form.getValue('variableB');
if (!variableA && !variableB) {
alert('Please provide a value for Variable A or attach a file.');
return false; // Prevent the form submission
}
return true; // Allow the form submission
})();
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi