cancel
Showing results for 
Search instead for 
Did you mean: 

API Response Sum function

akandan
Participant
0 Kudos

Hi Experts,

I have done a Get call using: https://apisalesdemo8.successfactors.com/odata/v2/EmpTimeAccountBalance?$filter=userId eq 'sfadmin' and timeAccountType eq 'TAT_VAC_REC'&$format=json

The results are shown below:

"d": { "results": [ { "__metadata": { "uri": "https://apisalesdemo8.successfactors.com:443/odata/v2/EmpTimeAccountBalance('fd5291034e254f43a292e09952e954f4')", "type": "SFOData.EmpTimeAccountBalance" }, "timeAccount": "fd5291034e254f43a292e09952e954f4", "balance": "24", "timeAccountType": "TAT_VAC_REC", "userId": "sfadmin", "accountClosed": false, "timeUnit": "DAYS" },

{ "__metadata": { "uri":

"https://apisalesdemo8.successfactors.com:443/odata/v2/EmpTimeAccountBalance('9465e64f43974b238a6aa97e32d4a67e')", "type": "SFOData.EmpTimeAccountBalance" }, "timeAccount": "9465e64f43974b238a6aa97e32d4a67e", "balance": "18", "timeAccountType": "TAT_VAC_REC", "userId": "sfadmin", "accountClosed": false, "timeUnit": "DAYS" } ] } }

I have configured my response:

You have {{api_service_response.value.body.d.results.[0].balance}} days which returns the result:

You have 24 days

How can i sum up the values in both [0] and [1] to return the total of 42 Days?

Thanks!

Ashlin

Accepted Solutions (1)

Accepted Solutions (1)

JonasB
Contributor

Hi Ashlin,

if you always expect exactly two results, you can use the „add“ helper - see Scripting Syntax:

{{add api_service_response.value.body.d.results.[0].balance api_service_response.value.body.d.results.[1].balance}}

In case there can be more results than only two, you can instead also use the "sum" helper, which expects an array. To extract the balance values for all results, you can combine it with the "pluck" helper.

{{sum (pluck api_service_response.value.body.d.results "balance") }}

Regards
Jonas

akandan
Participant
0 Kudos

Thanks for the Link and the syntax.

Works perfect!

Answers (0)