GlideModalForm - Client
The GlideModalForm API provides methods to display a form in a GlideModal.
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.
| Name | Type | Description |
|---|---|---|
| title | String | Modal form title. |
| tableName | String | Table being shown. |
| onCompletionCallback | Function | Function to call after the form has been submitted and processed on the server.
The callback function has the form
|
| readOnly | Boolean | Optional. Flag that indicates whether the modal form should be set to read
only. Valid values:
Default: false |
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.
| 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. |
| Type | Description |
|---|---|
| void |
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.
| Name | Type | Description |
|---|---|---|
| sys_id | String | The id preference. One of the query parameters passed to the form. |
| Type | Description |
|---|---|
| void |
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.
| 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:
|
| Type | Description |
|---|---|
| void |
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.
| Name | Type | Description |
|---|---|---|
| callbackFunction | Function | Function to call after the form has been loaded. The callback function has the
form callBackFunction(GlideModalForm obj) |
| Type | Description |
|---|---|
| void |
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.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| void |
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();
}