- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2022 12:20 AM
Hello folks,
I'm working on an exercise to create a business rule to get the reference of the challenge, probably with getRefRecord(), then find all of the contribution records associated with this challenge record to calculate the total sum of contribution records and then store the value in the challenge record, field 'Current status'.
I wanted to do it with the GlideAggregate but I'm really struggling with how to search for the records associated with the challenge and then store them. Btw,can't use calculated value
Hopefully this makes sense. Any help or suggestions are greatly appreciated 🙂
So far, I come up with this.
var contributionGA = new GlideAggregate ('x_866947_gvs_sport_contribution');
contributionGA.addAggregate('SUM','contribution');
contributionGA.query();
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2022 04:19 AM
You are getting gliderecord in currentChallenge variable but you will have to dot walk to current status to store value as shown below, Inside if condition, you would need to write below line :
currentChallenge.current_status=contributionGA.getAggregate('SUM',"contribution"); //change field backend from current_status if needed
currentChallenge.update();
Also your 5th line should be as below,
contributionGA.addQuery("challenge",current.challenge);
Please mark this as Correct or Helpful if it helps.
Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2022 12:51 AM
You would just need to add filter for current record so that it wil pickup only those contributions.
e.g. If you are planning to write BR on Challenge table then you can use below script
var contributionGA = new GlideAggregate ('x_866947_gvs_sport_contribution');
contributionGA.addQuery("challenge",current.sys_id);
contributionGA.groupBy("challenge");// your current record field name on contribution table
contributionGA.addAggregate('SUM','contribution');
contributionGA.query();
if(contributionGA.next()){
current.u_current_status=contributionGA.getAggregate('SUM',"contribution");
}
In case if you have glideobject in other variables, getting via getRefRecord method then replace current with that gliderecord variable.
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2022 03:32 AM
Hello Abhijit,
thank you very much for your response. However, this is somehow not working for me. Is it because that 'challenge" field is not on the Contribution table but the Challange table?
For the getRefRecord, would be something like this?
var currentChallenge = current.challenge.getRefRecord();
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2022 03:53 AM
Are you writing BR on challenge table?
if yes then you don't need to get challenge gliderecord again, it already exist with current object.
if no then please provide information like on which table you are writing BR? Please share BR scrrenshot which will inlcude table, condtion and script details so that I can help you further.
Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2022 04:04 AM