Error in onsubmit script, help?

Julius28
Tera Expert

Hi folks,

 

Looks like I have issue in my on submit script and I cannot find the solution for now.

So I have catalog item form in portal(request form). The goal is to display an alert and block submit if in case specific values are selected. In my example, if in multiple choice field called "severity" user picks option "information" and in next field they select in ''first_line'' support one specific sys id, it should show alert as in my code and + block submit.

function onSubmit() {
(function() {
    var specificGroupSysID = '1911367437e72200d540d0d543990e1d'; //  specific assignment group sys ID
    var severityLevel = 'Information'; // Severity level 

    
    g_form.OnSubmit(function() {
        var selectedGroup = g_form.getValue('first_line');
        var selectedSeverity = g_form.getValue('severity');

        // Check if the selected group matches the specific sys ID and severity level is Information
        if (selectedGroup == specificGroupSysID && selectedSeverity == severityLevel) {
            // Show an alert
            alert('You cannot send "info" severity alert to this first line assignment group.');
            // Cancel the submission
            g_form.setAbortAction(true);
        }
    });
})();   
}

Do you see where i have error? or  can you show how to make this script more efficient if its possible?

 

Thanks.

 

1 ACCEPTED SOLUTION

Hi @Julius28 here is the updated script

function onSubmit() {

var specificGroupSysID = '1911367437e72200d540d0d543990e1d'; // specific assignment group sys ID
var severityLevel = 'Information'; // Severity level

var selectedGroup = g_form.getValue('first_line');
var selectedSeverity = g_form.getValue('severity');

// Check if the selected group matches the specific sys ID and severity level is Information
if (selectedGroup == specificGroupSysID && selectedSeverity == severityLevel) {
// Show an alert
alert('You cannot send "info" severity alert to this first line assignment group.');
// Cancel the submission
return false;
}

}

Regards
Harish

View solution in original post

5 REPLIES 5

Harish KM
Kilo Patron
Kilo Patron

Hi @Julius28 can you change the below line

g_form.setAbortAction(true); to return false;

Regards
Harish

Julius28
Tera Expert

Hi @Harish KM , still not working, also getting in console this error: TypeError: g_form.OnSubmit is not a function

something wrong there?

Hi @Julius28 here is the updated script

function onSubmit() {

var specificGroupSysID = '1911367437e72200d540d0d543990e1d'; // specific assignment group sys ID
var severityLevel = 'Information'; // Severity level

var selectedGroup = g_form.getValue('first_line');
var selectedSeverity = g_form.getValue('severity');

// Check if the selected group matches the specific sys ID and severity level is Information
if (selectedGroup == specificGroupSysID && selectedSeverity == severityLevel) {
// Show an alert
alert('You cannot send "info" severity alert to this first line assignment group.');
// Cancel the submission
return false;
}

}

Regards
Harish

Robin Hogli
Tera Contributor

Hello. Can you try to remove "g_form.OnSubmit(function() {" from your script? You already declare this in the top of your code. The updated code would look like this. 

function onSubmit() {

    var specificGroupSysID = '1911367437e72200d540d0d543990e1d'; //  specific assignment group sys ID
    var severityLevel = 'Information'; // Severity level

   
 
        var selectedGroup = g_form.getValue('first_line');
        var selectedSeverity = g_form.getValue('severity');

        // Check if the selected group matches the specific sys ID and severity level is Information
        if (selectedGroup == specificGroupSysID && selectedSeverity == severityLevel) {
            // Show an alert
            alert('You cannot send "info" severity alert to this first line assignment group.');
            // Cancel the submission
            return false;
        }
}