- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2016 05:36 AM
Hi Team,
Reaching out for expert eyes again !
I am trying to capture the total hrs logged on all timecards for a particular Master Record.
This onLoad is on the form for Master Record.
The Master Record has currently 6 timecards associated with it and I do get the alert 6 times which means the records are fetched.
However, the gr1.total value is blank and not returning any value. For that matter, I tried few more values out of that glide record but no success.
function onLoad() {
var est_hrs_utilised = 0;
g_form.setValue("u_estimated_hours_utilized",est_hrs_utilised);
var vsar_sysid = g_form.getUniqueValue();
alert(vsar_sysid);
var gr1 = new GlideRecord('time_card');
gr1.addQuery("state", 'Approved').addOrCondition("state", 'Processed');
gr1.addQuery("u_vsar", vsar_sysid);
gr1.query();
while(gr1.next())
{
alert("I am in :" , gr1.total);
est_hrs_utilised = est_hrs_utilised + gr1.total ;
}
g_form.setValue("u_estimated_hours_utilized",est_hrs_utilised);
}
Regards
Nitin
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2016 05:43 AM
While I recommend you use a GlideAjax call to do this (much easier to debug and maintain)...
Try changing the gr1.total to gr1.getValue('total');
You may also need to do a parseFloat() to convert it to a decimal if JavaScript thinks it is a string. Hopefully not, but be aware.
Use a "+" instead of a "," in alert for best results.
alert("I am in :" + gr1.getValue('total');
est_hrs_utilised = est_hrs_utilised + gr1.getValue('total') ;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2016 05:43 AM
While I recommend you use a GlideAjax call to do this (much easier to debug and maintain)...
Try changing the gr1.total to gr1.getValue('total');
You may also need to do a parseFloat() to convert it to a decimal if JavaScript thinks it is a string. Hopefully not, but be aware.
Use a "+" instead of a "," in alert for best results.
alert("I am in :" + gr1.getValue('total');
est_hrs_utilised = est_hrs_utilised + gr1.getValue('total') ;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2016 05:45 AM
In alert you have to use + in place of ,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2016 06:03 AM
Hi Nitin,
Are you working in scoped application? If you answer is yes, then GlideRecord no longer works in Client script when working in Scoped Application.
I would recommend you to use as GlideAjax.
Thanks
Abhishek
PS - Please mark this Helpful, Like, or Correct Answer if relevant.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2016 07:12 AM
Thanks a lot Chuck, Gurpreet and Abhishek.
Your inputs helped a lot.
The strange part was that I had to rearrange my addQueries and the code worked.
As Chuck rightly mentioned, the output was being treated as a string and hence I had to use parseFloat() .
Chuck,
I did not try getValue() since I was able to get the value without it.
Sincerely appreciate the help you provide to novices like me.
Regards
Nitin