- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 04:18 AM
Hi,
I am working on some PPM kind of project, the requirement is something
there are three fields 'u_total' , 'u_mdc' and 'u_tpc'
'u_total' This field should be the sum of all the records of fields ('u_mdc' and 'u_tpc' ) that are available in the table
Anyone can help with this,
Note: All three fields are decimal fields.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 04:51 AM - edited 07-23-2023 04:53 AM
If you might need to this for new records then you can run a scheduled job with the desired frequency or tweak this into a BR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 09:20 PM - edited 07-23-2023 09:21 PM
@Atik You will have write a script to update the records that were created earlier.
Please use the code below to run in the background script/ Fix script, this will retrieve all the records which has values for MDC or TPC and update the total field with the sum of MDC & TPC.
In the script, please change the table_name in the line number 1 to the actual table name.
var projects=new GlideRecord('table_name');
//please replace the table_name with the actual table name.
projects.addEncodedQuery('u_mdcISNOTEMPTY^ORu_tpcISNOTEMPTY');
projects.query();
while(projects.next()){
projects.u_total=projects.u_mdc+projects.u_tpc;
project.update();
}
Please mark the appropriate response as correct answer and helpful.
Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 04:39 AM
@Atik You can navigate to the respective screen and right click on the grey area in the screen and select configure--> Business Rule
in the screen that appears, click on the new button to create a new business rule and enter the below details.
Name:- Calculate Total
Advanced:- True
When:- before
Insert & update:- True
Add the below code in the Advanced tab and submit the business rule.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
current.u_total=current.u_mdc+current.u_tpc;
})(current, previous);
After the creation of the business rule the total should be calculated automatically when the record is saved.
Please mark the appropriate response as correct answer and helpful.
Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 04:48 AM
Hi @Arun_S1 ,
It should also include the previously available record's value of respective fields in the table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 09:20 PM - edited 07-23-2023 09:21 PM
@Atik You will have write a script to update the records that were created earlier.
Please use the code below to run in the background script/ Fix script, this will retrieve all the records which has values for MDC or TPC and update the total field with the sum of MDC & TPC.
In the script, please change the table_name in the line number 1 to the actual table name.
var projects=new GlideRecord('table_name');
//please replace the table_name with the actual table name.
projects.addEncodedQuery('u_mdcISNOTEMPTY^ORu_tpcISNOTEMPTY');
projects.query();
while(projects.next()){
projects.u_total=projects.u_mdc+projects.u_tpc;
project.update();
}
Please mark the appropriate response as correct answer and helpful.
Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 04:51 AM - edited 07-23-2023 04:53 AM
If you might need to this for new records then you can run a scheduled job with the desired frequency or tweak this into a BR.