Page is loaded to request submission

Anmol8
Mega Guru

On my catalog item, I want to stay on same page if form is restricted by client script to submit request.

But after I click submit it moves to request page , I want to restrict that.

Anmol8_0-1720604213654.png

 

 

Regards,

Anmol

5 REPLIES 5

Zach Koch
Giga Sage
Giga Sage

I'm not sure I understand your question. Are you asking for a client script to restrict submission or do you already have a client script that does that, but you're saying it's still submitting and moving to next page when it shouldn't?

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

@Zach Koch I created a client script which restricts submission. And here that client scripts restrict new record but it moves the catalog item variable page to request created form as per the screen shot.

 

Can you post screenshots of your client script? If your client script is preventing submission, the UI action shouldn't redirecting the page.

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

function onSubmit() {
    console.log("onSubmit function started");
    var groupName = g_form.getValue('assignment_group')+'_sn'; // Replace 'group_name' with the actual field name
    console.log("Group Name:", groupName);

    if (!groupName) {
        console.log("Group Name is empty");
        return true; // Allow form submission if the group name is empty
    }

    var ga = new GlideAjax('ITIL_group_cat_item');
    ga.addParam('sysparm_name', 'isGroupExists');
    ga.addParam('groupName', groupName);

    ga.getXML(function(response) {
        console.log("AJAX response received");
        var groupExists = response.responseXML.documentElement.getAttribute("answer");
        console.log("Group Exists:", groupExists);
        if (groupExists === 'true') {
            //alert('The group name already exists. Please enter a different name.');
            //clear value
            g_form.clearValue('assignment_group');
            g_form.addErrorMessage('The group name already exists. Please enter a different name and submit request again.');
            //g_form.submit(false);
            return false;
        } else {
            return true;
        }
    });

   // return false; // Prevent form submission until the AJAX call completes
}