Rhino Exception Error
						
					
					
				
			
		
	
			
	
	
	
	
	
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 03:38 AM
Hi,
I have a requirement to populate ‘Owning IT Service’ on existing RCCF(custom table) records. I have created an on demand scheduled job with following script to populate the IT Service, this schedule job uses a function from existing script include. I have tested the functionality of this function using a background script and passing an example sys_id of CI. But when I try to send the sys_id of the CI using script it's throwing an error, following is the script and the error I am getting
var util = new global.BPCIUtils();
var rccf = new GlideRecord('u_root_cause_cf');
rccf.addQuery('business_service', '');
rccf.query();
gs.log('Total Records: ' + rccf.getRowCount(), 'RCCF');
while(rccf.next()){
var ci = rccf.cmdb_ci;
rccf.business_service = util.getOwningITService(ci); // Error Line
rccf.setWorkflow(false);
rccf.autoSysFields(false);
rccf.update();
}
It is not working and throwing the following error at line 8 ie., rccf.business_service = util.getOwningITService(ci);
type:error, message: Illegal access to getter method getMessage in class org.mozilla.javascript.RhinoException
Please help me solve this issue.
Thanks,
Nitin
- Labels:
- 
						
							
		
			Problem Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 03:59 AM
Hi Nitin,
Is your scheduled job also in same scope as that of the script include?
Can you check & share the code inside the function getOwningITService()?
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 04:04 AM
The scheduled job and the script include are in the same scope. Following is the code inside funtion
getOwningITService: function (ci) {
// This function should return the sys_id of the owning IT Service detemined by the passed sys_id of the ci.
try {
 var useIteration = true;
 var owningService = '';
 var gr = new GlideRecord("cmdb_ci");
 gr.get(ci);
 var ciClass = gr.sys_class_name;
 var extCi = new GlideRecord(ciClass);
 extCi.get(ci);
// Apply a forced check for particular CI Classes.
 if (owningService == '') {
 switch (ciClass.toString()) {
 case 'u_cmdb_ci_spkg_application_deploy': //application Deployment
 //application packages have parent cation packeges within this would need to be re-written
 owningService = extCi.u_application_package.u_it_service;
 break;
 default:
 break;
 }
 }
//check to see if CI is extended from the business service class.
 if (owningService == '') {
 var bStable = new TableUtils("cmdb_ci_service");
if (bStable.getHierarchy().indexOf(ciClass) != -1) {
 owningService = ci;
 }
 }
//Check to see if CI It Service rel is available if it is then set
 if (extCi.u_it_service != '') {
 owningService = extCi.u_it_service;
 }
//Iterate through the CI parent relationships 2 levels
 if (!owningService && useIteration == true) {
 var relCi = new GlideRecord('cmdb_rel_ci');
 var child = ci;
 relCi.addQuery('child', child);
 relCi.addNotNullQuery('parent');
 relCi.query();
 while (relCi.next()) {
 //check parent level 1
 if (owningService != '') break;
 //check parent class is a business Service
 var parent1BS = new TableUtils("cmdb_ci_service");
 if (parent1BS.getHierarchy().indexOf(relCi.parent.sys_class_name) != -1) {
 owningService = relCi.parent;
 break;
 }
 if (relCi.parent.u_it_service != '') {
 owningService = relCi.parent.u_it_service;
 break;
 } else {
 //check the parent level 2
 var parentCi = new GlideRecord('cmdb_rel_ci');
 var child1 = relCi.parent;
 parentCi.addQuery('child', child1);
 parentCi.addNotNullQuery('parent');
 parentCi.query();
 while (parentCi.next()) {
if (owningService != '') break;
 //check parent level 2
var parent2BS = new TableUtils("cmdb_ci_service");
 if (parent2BS.getHierarchy().indexOf(parentCi.parent.sys_class_name) != -1) {
 owningService = parentCi.parent;
 break;
 }
if (parentCi.parent.u_it_service != '') {
 owningService = parentCi.parent.u_it_service;
 break;
 }
 }
 }
 }
 }
//If not found the mark as an orphan and assing to configuration management
 // Discuss strategy here
return owningService;
} catch (e) {
 this.logError('global.BPCIUtils.getOwningITService', e.message);
 } finally { }
 },
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 04:13 AM
Hi,
you will have to add log statements one by one in the script include function to check and debug
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 04:19 AM
As I have mentioned in the post, the function is working if I pass the sys_id of the ci directly. I have tested it in a background script. It is not working when I am passing the sys_id by gliding to a table. So there's nothing wrong with the script include.
Thanks,
Nitin.
