Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

How to display a pop-up confirmation

Harsha38
Tera Guru

I want to Display a pop-up confirmation with YES or NO  when the HR Service is ‘Hire’ and state changes to close complete without using a UI Action in Workspace. Please help me here.

@Ankur Bawiskar 
@Ravi Gaurav 
@Jaspal Singh4 
@Ravi Chandra_K 
@Dr Atul G- LNG 
@Mohith Devatte 
@hvrdhn88 
@Mohith Devatte 

7 REPLIES 7

Tanushree Maiti
Kilo Patron

Hi @Harsha38 ,

Use g_modal.confirm() to create the Yes/No dialog and g_form.submitted = false within the rejection function to stop submission

 

Refer: g_modal ( Next Experience ) - Client 

 

Sample code  for  UI action:

 

function onUIActionClick() {
    var state = g_form.getValue("state");
var closeCompleteState = '3'; // please replace the value with your 'Close Complete' value
    var hireServiceSysId = 'UR_HireService_SYS_ID'; // Replace with your Hire HR Service Sys ID
      
    if (state == closeCompleteState && hrService == hireServiceSysId) {
          if (g_form.submitted) return; 
 
    g_modal.confirm('Confirmation','Are you sure you want to close this Hire case?', {
            confirmTitle: 'Yes',
            cancelTitle: 'No'
}).then(
function() {
  g_form.submitted = true;
              g_form.submit();
 
            }, 
function() {
            g_form.submitted = false;
        });
 
    return false;
 
}

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

After clicking on Yes, the form was not saved. Could you please assist here. Thank you

@Harsha38 ,

Try this script once,

function onUIActionClick() {
    var state = g_form.getValue("state");
    var hrService = g_form.getValue("hr_service");

    var closeCompleteState = '3';
    var hireServiceSysId = 'UR_HireService_SYS_ID';

    if (state == closeCompleteState && hrService == hireServiceSysId) {

        if (g_form.submitted) return false;

        g_modal.confirm('Confirmation', 'Are you sure you want to close this Hire case?', {
            confirmTitle: 'Yes',
            cancelTitle: 'No'
        }).then(function () {
            g_form.submitted = true;
            g_form.submit('save');
        }, function () {
            g_form.submitted = false;
        });

        return false;
    }
}

Best Regards,

Dinesh.