Changing the Duration Field Value

abdul_qulatein
Giga Expert

I am trying to change the value of a duration field after the change record has been inserted. It should count how many affected CI are associated to the change record then change the current value of the duration field by multiplying the current value to number of CIs found.

I have this business rule in place, but doesn't appear to be working:

setEstimatedTime();

function setEstimatedTime() {

  var aciRecord = new GlideRecord('task_ci');

  aciRecord.addQuery('task', current.sys_id);

  aciRecord.query();

  gs.log('Affected CI Records found: ' + aciRecord.getRowCount());

  var ciRowCount = aciRecord.getRowCount();

  var eTime = current.u_estimated_time.dateNumericValue();

  eTime = eTime * ciRowCount;

  current.u_estimated_time.setDateNumericValue(eTime);

}

Any suggestions?

Many thanks.

1 ACCEPTED SOLUTION

Thanks March, that did the trick here is the updated script for anyone to re-utilize;



setEstimatedTime();



function setEstimatedTime() {


  var aciRecord = new GlideRecord('task_ci');


  aciRecord.addQuery('task', current.sys_id);


  aciRecord.query();


  gs.log('Affected CI Records found: ' + aciRecord.getRowCount());


  var ciRowCount = aciRecord.getRowCount();


  var eTime = current.u_time_per_unit.dateNumericValue();


  eTime = Number(eTime) * ciRowCount;


  current.u_estimated_time.setDateNumericValue(eTime);


}



I've had to create a new duration field to store the original time value then multiply it by the number of row returned from the query.


View solution in original post

2 REPLIES 2

march
Kilo Guru

Try replacing


eTime = eTime * ciRowCount;


with


eTime = Number(eTime) * ciRowCount;


Thanks March, that did the trick here is the updated script for anyone to re-utilize;



setEstimatedTime();



function setEstimatedTime() {


  var aciRecord = new GlideRecord('task_ci');


  aciRecord.addQuery('task', current.sys_id);


  aciRecord.query();


  gs.log('Affected CI Records found: ' + aciRecord.getRowCount());


  var ciRowCount = aciRecord.getRowCount();


  var eTime = current.u_time_per_unit.dateNumericValue();


  eTime = Number(eTime) * ciRowCount;


  current.u_estimated_time.setDateNumericValue(eTime);


}



I've had to create a new duration field to store the original time value then multiply it by the number of row returned from the query.