Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to set “Planned Benefit” and "Actual Benefit" to Project Workspace Financials Widgets

WataruS
Tera Contributor

 

I would like to add “Planned Benefit” and "Actual Benefit" to Project Workspace Financials Widgets.

I changed the widget settings and they will be reflected as shown below.

WataruS_0-1759890139148.png

 

However, there are currently two problems:

- The amount is displayed in two rows, one in red and one in black.

- Even when I enter values ​​into "Planned Benefit" and "Actual Benefit," the value does not change from 0 yen, and the correct number is not displayed.

 

The current widget settings are as follows:

■Planned Benefit

WataruS_1-1759890457102.png

 

■Actual Benefit(Designated as a child of Planned Benefit)

WataruS_2-1759890491258.png

 

Could you please let me know if there is an error in the setup?

 

1 ACCEPTED SOLUTION

M Iftikhar
Tera Sage

Hello @WataruS,

 

The issue is with how the widget script fetches data. The context object doesn’t include benefits or actual_benefit, which is why you’re seeing 0 yen. 

Try updating your script like below: 

Planned Benefit: 

var context = JSON.parse(context); 
var investment = context.investment; 
 
(function getPlannedBenefit() { 
   var invGR = new GlideRecord('sn_invst_pln_invst_investment'); 
   if (invGR.get(investment.sys_id)) { 
       var plannedBenefit = invGR.getValue('planned_benefit'); 
       return { 
           value: plannedBenefit, 
           displayValue: PPMCurrencyHelper.getFormattedAmountWithCurrency(plannedBenefit) 
       }; 
   } 
})(); 
 

Actual Benefit: 

var context = JSON.parse(context); 
var investment = context.investment; 
 
(function getActualBenefit() { 
   var invGR = new GlideRecord('sn_invst_pln_invst_investment'); 
   if (invGR.get(investment.sys_id)) { 
       var actualBenefit = invGR.getValue('actual_benefit'); 
       return { 
           value: actualBenefit, 
           displayValue: PPMCurrencyHelper.getFormattedAmountWithCurrency(actualBenefit) 
       }; 
   } 
})(); 
 

Also, the two-row (red/black) display happens when both value and displayValue are formatted twice. Make sure your widget isn’t applying extra formatting rules. 

 

MIftikhar_0-1759927109960.png

MIftikhar_2-1759927178787.png

If my response helped, please mark it as the accepted solution so others can benefit as well. 

 

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

View solution in original post

1 REPLY 1

M Iftikhar
Tera Sage

Hello @WataruS,

 

The issue is with how the widget script fetches data. The context object doesn’t include benefits or actual_benefit, which is why you’re seeing 0 yen. 

Try updating your script like below: 

Planned Benefit: 

var context = JSON.parse(context); 
var investment = context.investment; 
 
(function getPlannedBenefit() { 
   var invGR = new GlideRecord('sn_invst_pln_invst_investment'); 
   if (invGR.get(investment.sys_id)) { 
       var plannedBenefit = invGR.getValue('planned_benefit'); 
       return { 
           value: plannedBenefit, 
           displayValue: PPMCurrencyHelper.getFormattedAmountWithCurrency(plannedBenefit) 
       }; 
   } 
})(); 
 

Actual Benefit: 

var context = JSON.parse(context); 
var investment = context.investment; 
 
(function getActualBenefit() { 
   var invGR = new GlideRecord('sn_invst_pln_invst_investment'); 
   if (invGR.get(investment.sys_id)) { 
       var actualBenefit = invGR.getValue('actual_benefit'); 
       return { 
           value: actualBenefit, 
           displayValue: PPMCurrencyHelper.getFormattedAmountWithCurrency(actualBenefit) 
       }; 
   } 
})(); 
 

Also, the two-row (red/black) display happens when both value and displayValue are formatted twice. Make sure your widget isn’t applying extra formatting rules. 

 

MIftikhar_0-1759927109960.png

MIftikhar_2-1759927178787.png

If my response helped, please mark it as the accepted solution so others can benefit as well. 

 

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.