com.glide.script.RhinoEcmaError: Method "toString" called on incompatible object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2022 10:54 PM
I am calling the script include from BR and getting the below error
com.glide.script.RhinoEcmaError: Method "toString" called on incompatible object.
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
//gs.info('DC DevOps Fire BR');
DevOpsLogger.log('DC DevOps Fire BR');
gs.addInfoMessage('DC DevOps Fire BR start');
//var lt = new sn_devops.DevOpsPipelineExecutionDAO();
var lt = new DevOpsPipelineExecutionDAO();
gs.addInfoMessage('DC DevOps Fire BR lt '+lt);
var taskExecutionSysId = 'ffb445511b77495477cf98a98b4bcb79'; //TE0001921
lt.updateLeadTime(taskExecutionSysId);
gs.info('DC DevOps Fire BR end');
gs.addInfoMessage('DC DevOps Fire BR end');
})(current, previous);
Please assist me to overcome this issue.
Thanks,
Dinesh C
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2022 11:04 PM
I think toString() is used in your script include, can you check that where it is used and on what object?
Alternatively, you can paste the script here?
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2022 02:21 AM
Hi Raghav,
Thanks for your response. Please find below script.
updateLeadTime: function(taskExecutionSysId) {
var stepExecutionGr = new GlideRecordSecure("sn_devops_step_execution");
stepExecutionGr.addQuery("task_execution", taskExecutionSysId);
stepExecutionGr.setLimit(1);
stepExecutionGr.query();
gs.info('DC Devops SI stepExecutionGr '+stepExecutionGr.getRowCount());
if (stepExecutionGr.next()) {
if (!gs.nil(stepExecutionGr.end_time) &&
!gs.nil(stepExecutionGr.orchestration_task) &&
!gs.nil(stepExecutionGr.orchestration_task.step) &&
!gs.nil(stepExecutionGr.orchestration_task.step.type) &&
stepExecutionGr.orchestration_task.step.type == 'prod_deploy') {
var ga = new GlideAggregate("sn_devops_m2m_commit_execution");
var teID = stepExecutionGr.task_execution;
ga.addQuery('task_execution', teID);
ga.addAggregate('MIN', 'commit.work_item.start_date');
ga.groupBy('task_execution');
if (!gs.nil(teID)) {
ga.query();
if (ga.next()) {
var wipStartDate = ga.getAggregate('MIN', 'commit.work_item.start_date');
wipStartDate = new GlideDateTime(wipStartDate);
gs.info('DC DevOps wipStartDate '+wipStartDate);
gs.info('DC DevOps EndTime '+new GlideDateTime(stepExecutionGr.getValue("end_time")));
if (!gs.nil(wipStartDate)) {
var peGr = stepExecutionGr.pipeline_execution.getRefRecord();
if (peGr.isValidRecord()) {
var leadTime = GlideDateTime.subtract(wipStartDate, new GlideDateTime(stepExecutionGr.getValue("end_time")));
gs.info('DC DevOps leadTime '+leadTime);
peGr.setValue('lead_time', leadTime);
// peGr.update();
} else
this._logger.debug("Commit sys_id does not exist in the sn_devops_commit table");
} else
this._logger.debug("Commit reference is empty on sn_devops_m2m_commit_execution table. Please add commit reference");
} else
this._logger.debug("GlideAggregate did not return anything. Please check the queries");
} else
this._logger.debug("Task execution id does not exist in the sn_devops_step_execution table");
} else
this._logger.debug("Step execution doesn't meet criteria for calculating lead time");
} else
this._logger.debug("Step execution is invalid");
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2022 11:11 PM
Hi,
Did you check the script include function and debug it
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
07-08-2022 02:25 AM
Hi Aukur,
Thanks for your response. I have tried to debug the script from background but I got below error
Background message, type:error, message: Illegal access to private script include DevOpsPipelineExecutionDAO in scope sn_devops being called from scope global
Please find below script.
updateLeadTime: function(taskExecutionSysId) {
var stepExecutionGr = new GlideRecordSecure("sn_devops_step_execution");
stepExecutionGr.addQuery("task_execution", taskExecutionSysId);
stepExecutionGr.setLimit(1);
stepExecutionGr.query();
gs.info('DC Devops SI stepExecutionGr '+stepExecutionGr.getRowCount());
if (stepExecutionGr.next()) {
if (!gs.nil(stepExecutionGr.end_time) &&
!gs.nil(stepExecutionGr.orchestration_task) &&
!gs.nil(stepExecutionGr.orchestration_task.step) &&
!gs.nil(stepExecutionGr.orchestration_task.step.type) &&
stepExecutionGr.orchestration_task.step.type == 'prod_deploy') {
var ga = new GlideAggregate("sn_devops_m2m_commit_execution");
var teID = stepExecutionGr.task_execution;
ga.addQuery('task_execution', teID);
ga.addAggregate('MIN', 'commit.work_item.start_date');
ga.groupBy('task_execution');
if (!gs.nil(teID)) {
ga.query();
if (ga.next()) {
var wipStartDate = ga.getAggregate('MIN', 'commit.work_item.start_date');
wipStartDate = new GlideDateTime(wipStartDate);
gs.info('DC DevOps wipStartDate '+wipStartDate);
gs.info('DC DevOps EndTime '+new GlideDateTime(stepExecutionGr.getValue("end_time")));
if (!gs.nil(wipStartDate)) {
var peGr = stepExecutionGr.pipeline_execution.getRefRecord();
if (peGr.isValidRecord()) {
var leadTime = GlideDateTime.subtract(wipStartDate, new GlideDateTime(stepExecutionGr.getValue("end_time")));
gs.info('DC DevOps leadTime '+leadTime);
peGr.setValue('lead_time', leadTime);
// peGr.update();
} else
this._logger.debug("Commit sys_id does not exist in the sn_devops_commit table");
} else
this._logger.debug("Commit reference is empty on sn_devops_m2m_commit_execution table. Please add commit reference");
} else
this._logger.debug("GlideAggregate did not return anything. Please check the queries");
} else
this._logger.debug("Task execution id does not exist in the sn_devops_step_execution table");
} else
this._logger.debug("Step execution doesn't meet criteria for calculating lead time");
} else
this._logger.debug("Step execution is invalid");
},
Thanks,
Dinesh C