
mak1A4
Tera Guru
Options
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 07-17-2021 05:25 PM
When developing forms in ServiceNow I like to play around with g_form inside DevTools every so often, now with Agent Workspace this isn't quite so simple anymore as g_form isn't available globally as it used to be in UI16. With the following script you will get the g_form instance of the currently active tab inside Agent Workspace 🙂
function getGlideFormAW() {
document.getElementsByTagName("sn-workspace-content")[0].shadowRoot.querySelectorAll("now-record-form-connected")[0]
var firstContentChild = document.getElementsByTagName("sn-workspace-content")[0].shadowRoot
.querySelectorAll(".chrome-tab-panel.is-active")[0].firstChild;
var snWorkspaceFormEl;
if (firstContentChild.tagName == "NOW-RECORD-FORM-CONNECTED") {
snWorkspaceFormEl = firstContentChild.shadowRoot.querySelectorAll(".sn-workspace-form")[0];
} else {
snWorkspaceFormEl = firstContentChild.shadowRoot.querySelectorAll("now-record-form-connected")[0]
.shadowRoot.querySelectorAll(".sn-workspace-form")[0];
}
if (!snWorkspaceFormEl) throw "Couldn't find sn-workspace-form";
var reactInternalInstanceKey = Object.keys(snWorkspaceFormEl).find(function (objKey) {
if (objKey.indexOf("__reactInternalInstance$") >= 0) {
return true;
}
return false;
});
return snWorkspaceFormEl[reactInternalInstanceKey].return.stateNode.props.glideEnvironment._gForm;
}