修复脚本只更新一条记录
Fix Script Only Updating One Record
我是 Javascript 和 Servicenow 的新手,请多多包涵。我正在创建一个修复脚本来填充事件任务上的事件违规时间标签。它将显示与父事件相同的 SLA。我下面的脚本 returns 应该更新正确的记录数。然而,当我去更新我的第二个 GlideRecord 中的记录时,它只更新了一个记录(应该是大约 125)。我出于测试目的评论了代码的更新部分。有什么建议么?谢谢
var grSLA = new GlideRecord('u_incident_task');
grSLA.addEncodedQuery('u_incident_breach_timeISEMPTY^parentISNOTEMPTY^stateIN1,2,4');
grSLA.query();
var count=0;
gs.info("{0} of Itasks found to update", grSLA.getRowCount());
while (grSLA.next())
{
var ipar = grSLA.parent.sys_id;
}
gs.print(ipar);
var grName = new GlideRecord('task_sla');
grName.addQuery('task', ipar);
grName.addQuery('stage', 'in_progress');
grName.query();
while (grName.next())
{
var bTime = grName.planned_end_time.getDisplayValue();
grSLA.u_incident_breach_time=bTime; //sets the Incident Breach Time on the iTask
//grSLA.update();
count++;
}
我认为您需要将 task_sla
循环移动到 u_incident_task
循环中。
它只更新最后一个,因为 ipar
是循环中的最后一条记录。
var grSLA = new GlideRecord('u_incident_task');
grSLA.addEncodedQuery('u_incident_breach_timeISEMPTY^parentISNOTEMPTY^stateIN1,2,4');
grSLA.query();
var count=0;
gs.info("{0} of Itasks found to update", grSLA.getRowCount());
while (grSLA.next())
{
var ipar = grSLA.parent.sys_id;
gs.print(ipar);
var grName = new GlideRecord('task_sla');
grName.addQuery('task', ipar);
grName.addQuery('stage', 'in_progress');
grName.query();
while (grName.next())
{
var bTime = grName.planned_end_time.getDisplayValue();
grSLA.u_incident_breach_time=bTime; //sets the Incident Breach Time on the iTask
grSLA.update();
count++;
}
}
我是 Javascript 和 Servicenow 的新手,请多多包涵。我正在创建一个修复脚本来填充事件任务上的事件违规时间标签。它将显示与父事件相同的 SLA。我下面的脚本 returns 应该更新正确的记录数。然而,当我去更新我的第二个 GlideRecord 中的记录时,它只更新了一个记录(应该是大约 125)。我出于测试目的评论了代码的更新部分。有什么建议么?谢谢
var grSLA = new GlideRecord('u_incident_task');
grSLA.addEncodedQuery('u_incident_breach_timeISEMPTY^parentISNOTEMPTY^stateIN1,2,4');
grSLA.query();
var count=0;
gs.info("{0} of Itasks found to update", grSLA.getRowCount());
while (grSLA.next())
{
var ipar = grSLA.parent.sys_id;
}
gs.print(ipar);
var grName = new GlideRecord('task_sla');
grName.addQuery('task', ipar);
grName.addQuery('stage', 'in_progress');
grName.query();
while (grName.next())
{
var bTime = grName.planned_end_time.getDisplayValue();
grSLA.u_incident_breach_time=bTime; //sets the Incident Breach Time on the iTask
//grSLA.update();
count++;
}
我认为您需要将 task_sla
循环移动到 u_incident_task
循环中。
它只更新最后一个,因为 ipar
是循环中的最后一条记录。
var grSLA = new GlideRecord('u_incident_task');
grSLA.addEncodedQuery('u_incident_breach_timeISEMPTY^parentISNOTEMPTY^stateIN1,2,4');
grSLA.query();
var count=0;
gs.info("{0} of Itasks found to update", grSLA.getRowCount());
while (grSLA.next())
{
var ipar = grSLA.parent.sys_id;
gs.print(ipar);
var grName = new GlideRecord('task_sla');
grName.addQuery('task', ipar);
grName.addQuery('stage', 'in_progress');
grName.query();
while (grName.next())
{
var bTime = grName.planned_end_time.getDisplayValue();
grSLA.u_incident_breach_time=bTime; //sets the Incident Breach Time on the iTask
grSLA.update();
count++;
}
}