The GlideModalForm API provides methods to display a form in a GlideModal.

General usage of the GlideModalForm class involves creating the object, setting any preferences, and then rendering the GlideModalForm.
var dialog = new GlideModalForm('dialog title', 'table_name_or_form_name', [callback on completion of submit])
  dialog.setPreference('name', 'value');
  dialog.render();

Specify the query parameters that are passed to the form using the setPreference() method. Any name/value pair that you specify with setPreference() is sent along with the form POST request to display the form.

The GlideModalForm is set to fill the height of the document window.

GlideModalForm - GlideModalForm(String title, String tableName, Function onCompletionCallback, Boolean readOnly)

Creates an instance of the GlideModalForm class.

Example

This example shows how to instantiate a GlideModalForm object.

function openDevice(deviceSysID, deviceName) {
  var uName = gel('hidden_user_name').value + "'s ";
  deviceName = new String(deviceName).escapeHTML();
  var gp = new GlideModalForm(uName + deviceName, "cmn_notif_device", refreshNotifPage);
  gp.addParm('sys_id', deviceSysID);
  gp.render();
}

GlideModalForm - addParm(String name, String value)

Sets the specified form field to the specified value.

Table 2. Parameters
Name Type Description
name String Form field name. If the specified name is not a field in the associated modal form, it is ignored.
value String Value to set the specified form field to.
Table 3. Returns
Type Description
void

Example

This example shows how to call addParm() to set the value of the sys_id field the modal form.

function openDevice(deviceSysID, deviceName) {
  var uName = gel('hidden_user_name').value + "'s ";
  deviceName = new String(deviceName).escapeHTML();
  var gp = new GlideModalForm(uName + deviceName, "cmn_notif_device", refreshNotifPage);
  gp.addParm('sys_id', deviceSysID);
  gp.render();
}

GlideModalForm - setSysID(String sys_id)

Sets the object's sys_id preference.

Table 4. Parameters
Name Type Description
sys_id String The id preference. One of the query parameters passed to the form.
Table 5. Returns
Type Description
void

Example

This example shows how to use the setSysID() method to initialize the value of the sys_id.

function(startDate, endDate) {
  var dialog = new GlideModalForm("Add Schedule Item", "cmn_schedule_span");
  dialog.setSysID("-1");
  dialog.addParm("sysparm_collection", "cmn_schedule");
  dialog.addParm("sysparm_collectionID", this.sysId);
  dialog.addParm("sysparm_collection_key", "schedule");
 
  var q = "schedule=" + this.sysId + "^start_date_time="
   + startDate.serializeInUserFormat() + "^end_date_time="
   + endDate.serializeInUserFormat() + "^";

  if (startDate.isAllDay(endDate))
    q += "^all_day=true^";
 
  dialog.addParm("sysparm_query", q);
  dialog.render();
}

GlideModalForm - setCompletionCallback(Function callbackFunction)

Sets the function to be called when the form has been successfully submitted and processed by the server.

Table 6. Parameters
Name Type Description
callbackFunction Function Callback function to call when the form has been successfully processed.
The callback function has the form callbackFunction(String action_verb, String sys_id, String table, String displayValue) where:
  • action_verb: action_name from a sys_ui_action record
  • sys_id: Sys_id of the affected record
  • table: Name of the table containing the record
  • displayValue: Value that appears on the form
Table 7. Returns
Type Description
void

Example

This example shows how to set the onload callback function of the associated modal.

function handleCreateOrEdit(targetFieldName, sourceFieldName, adapterRuleId, transformerSysId){
  dialog = new GlideModalForm('Edit Adapter Rule', "sys_adapter_rule");
  dialog.setSysID(adapterRuleId); //Pass in sys_id to edit existing record
  dialog.addParm('sysparm_form_only', 'true'); //Add or remove related lists
  dialog.setOnloadCallback(hideModalForm);
  dialog.setCompletionCallback(handleAdapterCreatedOrUpdated);
  dialog.render(); //Open the dialog
}
function handleAdapterCreatedOrUpdated(action_verb, sys_id, table, displayValue) {
  var draftRecordTransformer = g_form.getValue("draft_record_transformer");
  if(draftRecordTransformer == null || draftRecordTransformer.length == 0) {
    //sync Sticky Replications if it is enabled.
    var ajax = new GlideAjax('ReplicationPoolUtil');
    ajax.addParam('sysparm_name', 'syncStickyReplicationSet');
    ajax.addParam('sysparm_entry_set', g_form.getValue("entry_set"));
    ajax.getXMLWait();
  }
}

GlideModalForm - setOnloadCallback(Function callbackFunction)

Sets the function to be called after the form has been loaded.

Table 8. Parameters
Name Type Description
callbackFunction Function Function to call after the form has been loaded. The callback function has the form callBackFunction(GlideModalForm obj)
Table 9. Returns
Type Description
void

Example

This example shows how to set the on load callback function of the associated modal.

function handleCreateOrEdit(targetFieldName, sourceFieldName, adapterRuleId, transformerSysId){
  dialog = new GlideModalForm('Edit Adapter Rule', "sys_adapter_rule");
  dialog.setSysID(adapterRuleId); //Pass in sys_id to edit existing record
  dialog.addParm('sysparm_form_only', 'true'); //Add or remove related lists
  dialog.setOnloadCallback(hideModalForm);
  dialog.setCompletionCallback(handleAdapterCreatedOrUpdated);
  dialog.render(); //Open the dialog
}

GlideModalForm - render()

Shows the modal form.

Table 10. Parameters
Name Type Description
None
Table 11. Returns
Type Description
void

Example

This example shows how to call render() to display the modal.

function openDevice(deviceSysID, deviceName) {
  var uName = gel('hidden_user_name').value + "'s ";
  deviceName = new String(deviceName).escapeHTML();
  var gp = new GlideModalForm(uName + deviceName, "cmn_notif_device", refreshNotifPage);
  gp.addParm('sys_id', deviceSysID);
  gp.render();
}