Barbara L - Gli
Tera Guru

A dialog can be utilized to carry out a bulk edit on one or more fields in list view using a built in method called showQuickForm. The user can check the records they’d like to update, open the dialog, input their values, submit and they’re done.

 

For example, a user could update the Priority and add a Comment to selected tasks.

 

find_real_file.png

 

Why use a dialog to update these fields?

 

If there is a need to perform server-side validation when performing a bulk update for records, update other dependent fields on the one being edited, etc. a dialog can be a good way to manage that without an additional business rule. You can also manage very specifically what fields are being updated in list view and by whom without editing any list ACLs. It’s also fairly user friendly.

 

How to use showQuickForm

 

 

SNGuru has a good section on how to use showQuickForm

 

The ServiceNow doc page on showQuickForm in contrast, without preamble, will not work in it's current form. It describes creating a business rule, which you then reference in your UI Action… It will not work if you follow their instructions. They mention some valid points about the method, but the instructions are incorrect. There are some community posts about this as well.

 

You set up the form similarly to below

  • Set Name, Table, and Action name
    • Action name can be any unique name for this UI Action
  • Check the Client Checkbox
  • Call showQuickForm in OnClick and pass in 2 arguments: view and action name
    • The view can be a custom view containing all the fields that need bulk updated. The default view would very likely have more fields on it than needed for the update
    • The action name is whatever unique action name you chose earlier
    • Check the box where you would like the action to appear on the list, such as List choice, when to show, etc.
    • The script field runs on the server side for each checked record, accessing the record via current. In the picture below you can see current.update() is present in the script field. This is required. If we didn’t tell the record to update, nothing would save when the dialog is submitted.

find_real_file.png

It is well utilized as a list choice because records are supposed to be checked to use it, but does not have to be. If it were used instead as a List banner button for example, and the user does not check any records an alert would show indicating there are no checked records and the dialog would not render.

find_real_file.png

This is the most simplistic way of using showQuickForm. A less documented possibility that extends the functionality is calling showQuickForm from the script field directly, and not just OnClick. This allows you to run client-side code before opening the dialog. Similar to the alert that pops up when there are no records checked, you could create your own alert when certain conditions are not met. You could use say a GlideAjax to perform some validation on the checked records before opening the dialog.

find_real_file.png

Additionally, in the source code (snippet below) you can see that showQuickForm accepts 4 arguments, rather than just the two (view and action_name) described above. You can choose the size of your dialog by passing the width and height.

showQuickForm(‘myViewName’,’myActionName’,’dialogWidth’,’dialogHeight’)

Below is a small excerpt of the code that renders the form. Width and Height are optional parameters that are set if both width and height are present.

function showQuickForm(id, action, width, height) {
	var gForm = new GlideDialogForm("", tableName+"_update");
	if (width && height)
		gForm.setDialogSize(width, height);
	gForm.addParm('sysparm_view', id);
	gForm.setMultiple(form);
	gForm.addParm('sysparm_checked_items', "sys_idIN" + keyset);
	if (action && action != '')
		gForm.addParm('sysparm_action_name', action);
	gForm.render();
}

It is a convenience that all of this functionality is built in. However, there are some serious limitations to this method:

  • Client Script and UI Policies do NOT work
    • Because of this the dialog lacks immediate user feedback on the form, and is a SERIOUS limitation
  • The Dialog name is not editable
    • It’s a minor annoyance that it says “Dialog” in the upper left corner, but depending on how detail oriented the company is it could be an issue
  • Only compatible with List V2

Despite these limitations, if a method is needed to bulk update a few fields with fairly simplistic requirements and validation, showQuickForm can be a very easy, quick, pre-built method to do so.

Version history
Last update:
‎05-27-2019 04:54 AM
Updated by: