Created
May 31, 2022 15:44
Display form in dialog in ServiceNow and pre-populate some fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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