Onsubmit client script not working in Service Portal

reddy8055
Tera Contributor

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,

9 REPLIES 9

SanjivMeher
Kilo Patron
Kilo Patron

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.

I am able to see the alerts but still form is able to submit from the portal view. Its working fine from CMS view

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.

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;
            }
        }

  

reshmapatil
Tera Guru

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:

  1. OnSubmit CS with UI Type 'Desktop'

reshmapatil_0-1671275361342.png

2. OnSubmit CS with UI Type 'Mobile/Service Portal'

reshmapatil_1-1671275457649.png

 

Regards,

Reshma

**Please mark my answer correct or helpful based on the impact**