- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2024 06:52 AM
Hello my code in business rule returns 'null' or empty value for every field I am trying to get using getValue();. I have a simple app with two tables (Amount_of_points and Sport_list). What I am trying to do is to setup a business rule which is triggered after I make a update/insert on form with Amount_of_points. On a form I will choose a sport to which I will give a certain number of points and I want those points to be counted in the total amount of the specific sport. Attached script does not work and it is not able to sum anything because field 'amount' is always empty for the busines rule script so I am basically sending nothing to me total number of points. Any idea why I am not able to read fields using getValue();? Thank you.
Script:
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2024 08:12 AM
Update the query condition as follows.
contributionGR.addQuery('sport', current.sport);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2024 07:42 AM
@Martin_samek This is how you can debug you script.
(function executeRule(current, previous) {
var sportGR = current.sport.getRefRecord();
var amountGR = new GlideRecord('Amount_of_points');
amountGR.addQuery('sport', sportGR.getUniqueValue());
amountGR.query();
gs.info('Row Count is '+ amountGR.getRowCount());
while (amountGR.next()) {
//even this part is returning 'null' into my log
gs.info("Amount is " + amountGR.getValue('amount') + ' ' +amountGR.getValue('sys_id') );
var sum = sum + parseInt(amountGR.getValue('amount'), 10);
}
sportGR.setValue('progress', sum);
sportGR.update();
})(current, previous);
Check what are you getting in above logs.
Thanks,
Harsh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2024 07:52 AM
@Martin_samek Can you try with this code? if row count is giving you 0 then your addQuery() is not working .
what is sport column on your gliderecord table ?
it seems like you should try with sys_id column in addQuery()?
eg:
var sportGR = current.sport.getRefRecord();
var amountGR = new GlideRecord('Amount_of_points');
amountGR.addQuery('sys_id', sportGR.getUniqueValue());
amountGR.query();
gs.info('Row Count is '+ amountGR.getRowCount());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2024 07:57 AM
Just a follow up to this advice. To debug this I also generally add a .getEncodedQuery() line to the log:
gs.info('Row Count is '+ amountGR.getRowCount() + '\nQuery: ' + amountGR.getEncodedQuery());
I will then right click on the table name in the glide query to open the definition and then update the query part of the URL with the encoded query provided in the log line.
This will give you the exact results of your query visually. 99% of the time I find an issue in the query which is easier to determine when shown in a list view.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2024 07:42 AM
Hi @Martin_samek,
Check any records are returning with below scrip before entering to loop
if (amountGR.hasNext()) {
gs.info("Records found");
while (amountGR.next()) {
sum = sum + parseInt(amountGR.getValue('amount'), 10);
}
} else {
gs.info("No records found ");
}
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2024 07:48 AM
No records found