Onsubmit client script not working in Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 09:52 AM
Hi,
Client Script onsubmit is not working in service portal and its working fine in CMS view.
function onSubmit() {
//Type appropriate comment here, and begin script below
var today = new Date();
var domain = g_form.getValue('domain');
var mrvs = g_form.getValue('vta_training_details'); // internal name of your MRVS
var total = 0;
// alert(mrvs);
var obj = JSON.parse(mrvs);
if ((obj.length == 0) && (domain == 'AD.COM')) {
g_form.addErrorMessage("No Certifications");
return false;
} else if (obj.length < 4 && (domain == 'nonprod.int') || (domain == 'int')) {
g_form.addErrorMessage("Please complete remaining courses");
return false;
} else {
for (var i = 0; i < obj.length; i++) {
var startDTe = obj[i].course_completed_date; // name of the MRVS variable
total = total + parseInt(obj[i]).course_completed_date; // give here the variable name for proportion
var startDateNum = getDateFromFormat(startDTe, g_user_date_format);
var coursedate = today - startDateNum;
//alert(coursedate);
var dayDifference = coursedate / (1000 * 60 * 60 * 24);
//alert(dayDifference);
if (dayDifference > 365) {
g_form.addErrorMessage("Course Completed Date should not be more than 365 days");
return false;
}
}
}
}
Thanks,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 10:14 AM
Hi there,
Please ensure that the UI Type field on your onSubmit client script is set to All:
Regards,
Chris Perry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 10:23 AM
Hi,
Yes, UI type is set to ALL. But its still not working.
Thanks,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 10:28 AM
Ok -- try re-writing your script as below:
function onSubmit() {
//Type appropriate comment here, and begin script below
if (g_scratchpad.isFormValid) {
return true;
}
var today = new Date();
var domain = g_form.getValue('domain');
var mrvs = g_form.getValue('vta_training_details'); // internal name of your MRVS
var total = 0;
// alert(mrvs);
var obj = JSON.parse(mrvs);
if ((obj.length == 0) && (domain == 'AD.COM')) {
g_form.addErrorMessage("No Certifications");
return false;
} else if (obj.length < 4 && (domain == 'nonprod.int') || (domain == 'int')) {
g_form.addErrorMessage("Please complete remaining courses");
return false;
} else {
for (var i = 0; i < obj.length; i++) {
var startDTe = obj[i].course_completed_date; // name of the MRVS variable
total = total + parseInt(obj[i]).course_completed_date; // give here the variable name for proportion
var startDateNum = getDateFromFormat(startDTe, g_user_date_format);
var coursedate = today - startDateNum;
//alert(coursedate);
var dayDifference = coursedate / (1000 * 60 * 60 * 24);
//alert(dayDifference);
if (dayDifference > 365) {
g_form.addErrorMessage("Course Completed Date should not be more than 365 days");
return false;
}
}
}
g_scratchpad.isFormValid = true;
g_form.submit(g_form.getActionName());
}
Regards,
Chris Perry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 10:38 AM
Tried this, its not working