OnSubmit client script for catalog task to display confirm popup when user click on save or update

Mohankumari
Tera Contributor

Hello,

I have created new catalog item, when I submit the form in TASK, I want to add confirm popup or alert on the catalog task(sc_task) when user make any changes to the field and  click on save or update without adding the Message to User comments.

 

I tried OnSubmit client script , but however the validation failing and update happening without confirm popup when no comments added also.

 

Thanks in advance.

1 ACCEPTED SOLUTION

Tanushree Maiti
Tera Patron

Hi @Mohankumari 

 

Share your onsubmit code. 

Are you using native ui or SOW?

 

If you are using g_form.getControl() method, check this KB: 

KB0547171 The g_form.getControl method does not work after ordering 

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

View solution in original post

4 REPLIES 4

Shaik Dimple
Kilo Sage

Hi @Mohankumari,

 

An onSubmit Client Script with "confirm()" should work on catalog task (sc_task). Could you share the script you have implemented?

Also, are you checking the Additional comments (comments) field or a different field? Seeing the script will help identify why the form is still updating without showing the confirmation.

 

Thanks.

function onSubmit() {
    //for  form1
     var citm1='a286264193d887101d2afc69a8083d697';  // ignore number

    /for form2
    var citm2='32dcf69e2b90d3907bc6ff28ce91bfd1';   // ignore number
   

   var currentcitm=g_form.getValue('request_item');
   if (currentcitm===citm1 || currentcitm===citm1){
    var comments = g_form.getValue('comments');

    if (comments === '') {
        if (!confirm(
                'If you update without a comment, no email will be sent.\n\n' +
                'Click OK to proceed with update, or Cancel to add a comment.'
        )) {
            return false;
            }
        }
       

    }

   }
   

Tanushree Maiti
Tera Patron

Hi @Mohankumari 

 

Share your onsubmit code. 

Are you using native ui or SOW?

 

If you are using g_form.getControl() method, check this KB: 

KB0547171 The g_form.getControl method does not work after ordering 

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

function onSubmit() {
    //for  form1
     var citm1='a286264193d887101d2afc69a8083d697';  // ignore number

 

    /for form2
    var citm2='32dcf69e2b90d3907bc6ff28ce91bfd1';   // ignore number
   

 

   var currentcitm=g_form.getValue('request_item');
   if (currentcitm===citm1 || currentcitm===citm1){
    var comments = g_form.getValue('comments');

 

    if (comments === '') {
        if (!confirm(
                'If you update without a comment, no email will be sent.\n\n' +
                'Click OK to proceed with update, or Cancel to add a comment.'
        )) {
            return false;
            }
        }
       

 

    }

 

   }