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:31 AM
I think you need to put some alert statements to understand why it is failing. I would suggest adding alert() in you client script where you think your script is failing.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 10:53 AM
I am able to see the alerts but still form is able to submit from the portal view. Its working fine from CMS view

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 11:05 AM
Which condition should stop from submitting? Can you add an alert there and print the variable value in the alert?
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 11:43 AM
It should stop submitting based on all the conditions below. I am getting error in console as unexpected end of json input now.
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; } }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2022 03:14 AM
Hi @reddy8055 ,
I also faced a similar issue once when while doing some validations before submitting of catalog form. It was working fine on the desktop side but not on the portal.
Then I created 2 Client Scripts:
- OnSubmit CS with UI Type 'Desktop'
2. OnSubmit CS with UI Type 'Mobile/Service Portal'
Regards,
Reshma
**Please mark my answer correct or helpful based on the impact**