The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Compute the sum of a String field and display it to a String field

dianemiro
Kilo Sage

Dear All,

We have a business rule to sum up all the Efforts <u_effort_man_day> of a CTASK and display it to the Demand field Estimated Effort <u_effort_man_days>. Here is my code:

var dmnd = new GlideRecord('dmn_demand');

dmnd.addQuery('u_demand',current.sys_id);

dmnd.query();

var ctsk = new GlideRecord('change_task');

ctsk.addQuery('sys_id',current.u_demand);

ctsk.query();

var parCtask = parseFloat(ctsk.u_effort_man_day.replace(/,/g,''));

if(dmnd.next()){

  var count = 0;

  while(ctsk.next()){

  if(ctsk.u_demand_task_type == 'screening'){

  count += parseFloat(parCtask);   //u_effort_man_days field on change task

  }

  }

  dmnd.u_effort_man_days = count; //u_effort_man_days field on demand

  dmnd.update();

}

Apparently, this code is not working. Can you tell me what's wrong? Many thanks.

1 ACCEPTED SOLUTION

Hi Shishir,



Thank you so much for your response, I appreciate your help. I was able to sum up the effort by using the below code:



var dmnd = new GlideRecord('dmn_demand');


dmnd.addQuery('sys_id',current.u_demand);


dmnd.query();


var ctsk = new GlideRecord('change_task');


ctsk.addQuery('u_demand',current.u_demand);


ctsk.query();


if(dmnd.next()){


            var count = 0;


            while(ctsk.next()){



                                if(ctsk.u_demand_task_type != 'screening'){


                                                              count += parseFloat(ctsk.u_effort_man_day);   //u_effort_man_days field on change task


                                                    }


            }



  dmnd.u_effort_man_days = count; //u_effort_man_days field on demand


  dmnd.update();


}


View solution in original post

10 REPLIES 10

you can refer the link below for more information about logs.



http://wiki.servicenow.com/index.php?title=Viewing_System_Logs#gsc.tab=0



i have learned without logs and comments script is not so developer friendly