- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 06:15 PM - edited 09-20-2023 08:25 PM
"When a specific field contains only an integer value, the form should be submitted. However, if any changes are made to the field's value using the browser's inspect tool, or if a string value is entered, the form should not be submitted, and an error message should be displayed. To achieve this, please use the following client-side script on submit:"
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 06:54 PM - edited 09-20-2023 07:35 PM
Hi @Dipu_9999
You can set the variable REGEX in type specification to "Number" for OOTB validation or you can can use the onSubmit client script I provided below.
Or Use the following code to allow only integers (replace with your variable names)
function onSubmit() {
var intVar = g_form.getValue('please_enter_value') + ''; //Replace with your form variable name
var regEx = /^[0-9]+$/;
if (regEx.test(intVar) == false) {
g_form.addErrorMessage("Please input a valid integer and resubmit the request.");
return false;
}
}
Or Use the following code to allow real numbers (replace with your variable names)
function onSubmit() {
var intVar = g_form.getValue('please_enter_value') + ''; //Replace with your form variable name
var regEx = /^(?:-(?:[1-9](?:\d{0,2}(?:,\d{3})+|\d*))|(?:0|(?:[1-9](?:\d{0,2}(?:,\d{3})+|\d*))))(?:.\d+|)$/;
if (regEx.test(intVar) == false) {
g_form.addErrorMessage("Please input a valid integer and resubmit the request.");
return false;
}
}
Please mark my answer helpful and accept as solution if it helped 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 01:19 AM
Hi @Dipu_9999 ,
It seems you are using Multi Row Variable Set. Try using the below code in onSubmit catalog client script at catalog item level (not at variable set level).
function onSubmit() {
var mrvs_data = JSON.parse(g_form.getValue('multi_row_variable_set_internal_name')); //Replace with your multi row variable set internal anme
var regEx = /^[0-9]+$/;
for (key in mrvs_data) {
if (regEx.test(mrvs_data[key].SIZE_IN_GB) == false) { //Replace with the varibale name of Size (in GB)
g_form.addErrorMessage("Please input a valid integer and resubmit the request.");
return false;
}
}
return true;
}
Please let me know if you still have issues.
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 02:14 AM
You are writing this client script in Variables set, the script I provided should be used at catalog level. In Your client script form, change the Applies To field to "A Catalog item" and a new field field will appear in place of Variable Set field that is Catalog Item, select your catalog item in which you are using this MRVS. See the screen shots below.
If you want to write your client script at Variable Set level only, let me know.
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 04:03 AM
@Dipu_9999 Unfortunately onSubmit will not work at variable set level. And I have tested this script in my PDI it is working fine. Could you please delete this and create a new onSubmit catalog client script at catalog level. And use the below script to get the alerts for debugging.
function onSubmit() {
var mrvs_data = JSON.parse(g_form.getValue('size_drive_partition_detail')); //Replace with your multi row variable set internal anme
var regEx = /^[0-9]+$/;
for (key in mrvs_data) {
alert("Iteration : " + key + " Value: " + mrvs_data[key].size);
alert(mrvs_data[key].size);
if (regEx.test(mrvs_data[key].size) == false) {
g_form.addErrorMessage("Please input a valid integer and resubmit the request.");
return false;
}
}
return true;
}
If you receive the alerts and still the validation is not working we have to check the variable names and all are configured correctly or not.
Please let me know if still the issue persists.
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 04:59 AM
Please see the results from my PDI
Invalid Integer Case:
Valid Integer Case:
Empty value Case:
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 06:25 AM
@Dipu_9999 try this script
function onSubmit() {
var mrvs_data = JSON.parse(g_form.getValue('size_drive_partition_detail')); //Replace with your multi row variable set internal anme
var regEx = /^[0-9]+$/;
for (key in mrvs_data) {
if (mrvs_data[key].size == '') {
g_form.addErrorMessage("Please fill the size(in GB) and submit.");
return false;
} else if (regEx.test(mrvs_data[key].size) == false) {
g_form.addErrorMessage("Please input a valid integer and resubmit the request.");
return false;
}
}
return true;
}
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 02:14 AM
You are writing this client script in Variables set, the script I provided should be used at catalog level. In Your client script form, change the Applies To field to "A Catalog item" and a new field field will appear in place of Variable Set field that is Catalog Item, select your catalog item in which you are using this MRVS. See the screen shots below.
If you want to write your client script at Variable Set level only, let me know.
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 02:33 AM
I Use this script on catalog variable also but it is still not working you can give me the solution for both way alternative from this script on catalog client script and whant to use on variable set also
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 04:03 AM
@Dipu_9999 Unfortunately onSubmit will not work at variable set level. And I have tested this script in my PDI it is working fine. Could you please delete this and create a new onSubmit catalog client script at catalog level. And use the below script to get the alerts for debugging.
function onSubmit() {
var mrvs_data = JSON.parse(g_form.getValue('size_drive_partition_detail')); //Replace with your multi row variable set internal anme
var regEx = /^[0-9]+$/;
for (key in mrvs_data) {
alert("Iteration : " + key + " Value: " + mrvs_data[key].size);
alert(mrvs_data[key].size);
if (regEx.test(mrvs_data[key].size) == false) {
g_form.addErrorMessage("Please input a valid integer and resubmit the request.");
return false;
}
}
return true;
}
If you receive the alerts and still the validation is not working we have to check the variable names and all are configured correctly or not.
Please let me know if still the issue persists.
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 04:38 AM
yes script is working find but requirement is if the integer is not there then form should be not able to submit only and only form will submit when integer is in the size field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 04:59 AM
Please see the results from my PDI
Invalid Integer Case:
Valid Integer Case:
Empty value Case:
Anvesh