Skip to content

Instantly share code, notes, and snippets.

@thisnameissoclever
Created May 31, 2022 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thisnameissoclever/b46599d6f10c6d53ec2b7b374b0f66c9 to your computer and use it in GitHub Desktop.
Save thisnameissoclever/b46599d6f10c6d53ec2b7b374b0f66c9 to your computer and use it in GitHub Desktop.
Display form in dialog in ServiceNow and pre-populate some fields
function showMyForm(){
var recordID = g_form.getUniqueValue() || "-1";
var recordTableName = g_form.getTableName();
var dialog = new GlideDialogForm('Update Record', recordTableName);
//Set to "-1" to show new record form instead
dialog.setSysID(recordID);
//If false, will show related lists as well.
dialog.addParm('sysparm_form_only', 'true');
//todo: Form view?
dialog.addParm('sysparm_view', 'SOME_VIEW_HERE');
//From SNGuru - Thanks!
dialog.setLoadCallback(function(iframeDoc) {
// To get the iframe: document.defaultView in non-IE, document.parentWindow in IE
var dialogFrame = 'defaultView' in iframeDoc ? iframeDoc.defaultView : iframeDoc.parentWindow;
dialogFrame.g_form.setValue('SOME_FIELD_HERE', 'NEW_VALUE_HERE');
dialogFrame = null;
});
//dialog.hideCloseButton(); //optional
dialog.render();
}
showMyForm();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment