The CreatorCon Call for Content is officially open! Get started here.

Confirming before deleting record

zschneider
Kilo Expert

So i've spent a lot of time researching the wiki for an answer to this and it's probably very simple, but I just can't find it.

I want to have the global delete UI Action load a confirm() to verify the click before SN deletes a record. Problem is that the confirm() is client-side only script and current.deleteRecord(); is a server-side only function.

Is there an easy way to have a confirmation box before running some script that ultimately ends with current.deleteRecord(); ?

Thanks!
Zach S.

7 REPLIES 7

Hi Zach,



Is the UI Action form related or list related. I find that the above function doesn't work for list choice and list context menu UI Actions. Could you confirm please?



Regards,


Bala


I don't believe client scripts run on the list view. So you would need to do the client script code inside the UI Action and trigger the server side code from inside the client side code.



I set up an example inside demo007 if you want to look at it: https://demo007.service-now.com/sys_ui_action_list.do?sysparm_userpref_module=3cd860520a0a0b34003bdd...



Action name: test_confirm


Client: true


Onclick: testConfirm()



script:


function testConfirm(){


  var answer = confirm("Are you sure you want to do this? This cannot be undone.");



  if (answer == false){


  return false;


  }



  //Call the UI Action and skip the onclick function


  gsftSubmit(null, g_form.getFormElement(), 'test_conform');


}




function confirm_confirm(){



  current.short_description = "Confirm used!";


  current.update();


}




confirm_confirm();


Hi Zach,



Thanks for the quick response.


But unfortunately gsftSubmit(null, g_form.getFormElement(), 'UI Action name'); will work only for form-type UI actions.


Check here http://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/


Client: True (MUST be checked)


Form button/Form Context Menu/Form Link: (UI Action must be one of these 'Form' types)




Regards,


Bala