Not able to get correct data using painless scripting

I'm having 3 different TEXT fields containing NUMBERS and i'm trying to add all those values to a new fields as numeric data.

one of those field is:
// deliveryGroups.0.deliveryGroupId : 1

the painless script i'm using is :
//doc['deliveryGroups.0.deliveryGroupId'].value+ doc['deliveryGroups.1.deliveryGroupId'].value+ doc['deliveryGroups.2.deliveryGroupId'].value+ doc['deliveryGroups.3.deliveryGroupId'].value+ doc['deliveryGroups.4.deliveryGroupId'].value

this leads to concatenation of numbers in all fields and i get a result as : 1 or 12 or 123 or 124 instead of 1 or 3 or 6 or 7.

can someone please help me out!

as you already mentioned that you have text fields, the content is treated as a string, so string concatenation happens.

Try casting the values into a number, i.e. using Long.valueOf() and then adding them,


1 Like

thanks a ton!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.