- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 03:20 AM
Hi All
I have a requirement where i need to present the submission of the catalog form.
i did write the following code:
function onSubmit() {
var sn=g_form.getValue('service');
var cbox1 = g_form.getValue('did_you_read_kb_document_kb0007347_please_refer_description_for_the_link_to_kb');
var cbox2 = g_form.getValue('do_you_agree_with_the_automatic_expiration_policy_of_the_license_mentioned_in_kb0007347');
if(sn== '155936831b268a908d8ddc6fe54bcb8b')
{
if(cbox1 !== 'true' || cbox2 !== 'true')
{
alert('Select both checkboxes to submit the form.');
return false;
}
return true;
}
}
But its preventing only when there is "155936831b268a908d8ddc6fe54bcb8b" but the sys id "155936831b268a908d8ddc6fe54bcb8b" can be with any values.
Here the sys id belongs to "Copilot for M365"
But copilot for M365 can have many values along with it.
Example: for the values below i am still able to submit.
How to achieve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 03:25 AM
Hi @phr,
please check below link:
https://www.servicenow.com/community/developer-forum/if-condition/m-p/1635449
Thank you, please make helpful if you accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 03:28 AM
Hi
For Service Portal script it can be done by
var sn=g_form.getDisplayValue('service'); //returns the names of the services and not sys_id
//We make all the names lowercase to be more accurate when validating
if(sn.toLowerCase().indexOf("some special name with only lowercase chars") > -1){
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 04:36 AM
Hi @phr ,
Please replace the below and try:
if(sn, 'IN', '155936831b268a908d8ddc6fe54bcb8b');
Final Code will look like:
function onSubmit() {
var sn=g_form.getValue('service');
var cbox1 = g_form.getValue('did_you_read_kb_document_kb0007347_please_refer_description_for_the_link_to_kb');
var cbox2 = g_form.getValue('do_you_agree_with_the_automatic_expiration_policy_of_the_license_mentioned_in_kb0007347');
if(sn, 'IN', '155936831b268a908d8ddc6fe54bcb8b');
{
if(cbox1 !== 'true' || cbox2 !== 'true')
{
alert('Select both checkboxes to submit the form.');
return false;
}
return true;
}
}
Please Mark My Response as Correct/Helpful based on Impact
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 05:06 AM
Try
var sn=g_form.getValue('service'); //returns the list if sys_ids in the field
//Check if the list contains the sys_id your are looking for
if(sn.indexOf("sys_id") > -1){
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 05:22 AM - edited 06-17-2024 05:24 AM
Hi @phr ,
What about includes() function in javascript. Can you try that to see if it helps you to achieve the desired result.
https://www.w3schools.com/jsref/jsref_includes.asp
Please review this line of code as well :
if(cbox1 !== 'true' || cbox2 !== 'true') : two times equal to is used instead of "!="
Please mark helpful/correct if my response helped you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 03:25 AM
Hi @phr,
please check below link:
https://www.servicenow.com/community/developer-forum/if-condition/m-p/1635449
Thank you, please make helpful if you accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 03:36 AM
Hi @Yashsvi ,
Since i need to pass only the sys id , i am not making use of the Alphabets.
Instead of "==" i need the "Contains" to be replaced.
How to achieve this for sys id?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 03:28 AM
Hi
For Service Portal script it can be done by
var sn=g_form.getDisplayValue('service'); //returns the names of the services and not sys_id
//We make all the names lowercase to be more accurate when validating
if(sn.toLowerCase().indexOf("some special name with only lowercase chars") > -1){
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 03:34 AM
Hi @Simon Christens ,
Since i need to pass only the sys id , i am not making use of the Alphabets.
How to achieve this for sys id?
Thank you