Javascript 修复仅更新一条记录的脚本

Javascript 修复仅更新一条记录的脚本,javascript,servicenow,Javascript,Servicenow,我是Javascript和Servicenow的新手,请容忍我。我正在创建修复脚本以填充事件任务上的事件违反时间标签。它将显示与父事件相同的SLA。下面的脚本返回了应该更新的正确记录数。但是,当我在第二个GlideRecord中更新记录时,它只更新一条记录(应该是125条左右)。出于测试目的,我对代码的更新部分进行了注释。有什么建议吗?谢谢 var grSLA = new GlideRecord('u_incident_task'); grSLA.addEncodedQuery('u_inci

我是Javascript和Servicenow的新手,请容忍我。我正在创建修复脚本以填充事件任务上的事件违反时间标签。它将显示与父事件相同的SLA。下面的脚本返回了应该更新的正确记录数。但是,当我在第二个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\u sla
循环移动到
u incident\u 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++;
    }
}

我认为您需要将
task\u sla
循环移动到
u incident\u 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++;
    }
}

谢谢你,柯克!很好,谢谢你,柯克!现在工作很完美。