- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2024 08:17 AM
I have a requirement to auto update the program budget based on project associated to it and notify to program manager is there is any change in budget.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2024 08:27 AM
Hi @Prakash_S ,
You can follow below steps.
1. create a notification on program table and trigger it on update and insert.
2. Add condition that budget changes.
3. Create a after business rule on project table and use below script.
(function executeRule(current, previous /*null when async*/) {
// Ensure the project is linked to a program
if (!current.primary_program) {
return;
}
var programID = current.primary_program;
var totalBudget = 0;
// Query all projects linked to the program
var projectGR = new GlideRecord('pm_project');
projectGR.addQuery('primary_program', programID);
projectGR.query();
while (projectGR.next()) {
totalBudget += parseFloat(projectGR.getValue('budget_cost') || 0);
}
// Update the program's total budget if it has changed
var programGR = new GlideRecord('pm_program');
if (programGR.get(programID)) {
var previousBudget = parseFloat(programGR.getValue('budget_cost') || 0);
if (previousBudget !== totalBudget) {
programGR.setValue('budget_cost', totalBudget);
programGR.update();
}
}
})(current, previous);
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2024 08:27 AM
Hi @Prakash_S ,
You can follow below steps.
1. create a notification on program table and trigger it on update and insert.
2. Add condition that budget changes.
3. Create a after business rule on project table and use below script.
(function executeRule(current, previous /*null when async*/) {
// Ensure the project is linked to a program
if (!current.primary_program) {
return;
}
var programID = current.primary_program;
var totalBudget = 0;
// Query all projects linked to the program
var projectGR = new GlideRecord('pm_project');
projectGR.addQuery('primary_program', programID);
projectGR.query();
while (projectGR.next()) {
totalBudget += parseFloat(projectGR.getValue('budget_cost') || 0);
}
// Update the program's total budget if it has changed
var programGR = new GlideRecord('pm_program');
if (programGR.get(programID)) {
var previousBudget = parseFloat(programGR.getValue('budget_cost') || 0);
if (previousBudget !== totalBudget) {
programGR.setValue('budget_cost', totalBudget);
programGR.update();
}
}
})(current, previous);
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------