
petercawdron
Kilo Guru
Options
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 01-27-2020 10:35 PM
There are times where you need to use a client script to interact with the angular scope, but as ServiceNow uses iframes (and some times, such as with modal windows, iframes within iframes), it can be frustrating to find the correct scope. Here's a script that MIGHT help (with the emphasis on might). YMMV
var thisJavascriptContext = window.frames[window.frames.length -1];
thisJavascriptContext.isAngularReady = function(){
if(thisJavascriptContext.angular.element('main').scope().page.title=='Loading...') {
window.setTimeout(function(){ thisJavascriptContext.isAngularReady(); },100);
}else{
console.log('%cThis is the "'+thisJavascriptContext.angular.element('main').scope().page.title + '" page', 'color:red');
console.log('%cThe angular scope for this page is...','color:red');
console.log(thisJavascriptContext.angular.element('main').scope());
if(thisJavascriptContext.angular.element('main').scope().page.title != 'Service Catalog'){updateDetails(recordProdVariable, whichButton);}
}
};
thisJavascriptContext.isAngularReady();
In this instance, I needed to find out when angular was REALLY ready (ie, not just when angular had loaded but when ServiceNow's angular libraries had finished loading and the widgets were ready to go). As you can see from the console window, it worked well...
Labels: