Convert set of strings to numbers in an expression

  • Asked
  • Active
  • Viewed 6319 times
0

Hi,

I have a code attribute with codes 1,2,...,10 in a multiple entity. When the user adds "n" entities to the form, the sum of the code values from 1 to "n" have to add up to 10.

I'd like to check the sum of these code values in a separate attribute. Since codes in code lists are strings, the values should be converted to numbers to be able to sum them. So I figured this should work:

Custom error check, expression: sum(number(parent()/stand/share)) = 10

However I get an error in the preview window: [RPC Fault faultString="Invalid argument type for 'sum': java.lang.Double"...

Is it possible to convert a set of strings to numbers? How can I do this? I would like to keep code list instead of a numeric attribute, if it's possible.

Thanks for your help!

0

Accepted answer

Hi Andras,

you can solve this issue by adding a new hidden calculated attribute that will transform your share code value into a number, for example share_num with an expression like number(share) and then you can use that attribute in the custom check expression, that will become something like sum(parent()/stand/share_num) = 10.

Thanks!

Your answer

Markdown text. Shortcuts: Ctrl+B bold, Ctrl+I italic, Ctrl+K link, Ctrl+E code, Ctrl+Shift+V paste as plain text. Tab indents list items and code; press Escape, then Tab, to leave the text box.

Insert an image

Say what the image shows, for people who can't see it.

Keyboard shortcuts

Anywhere

?
Show this list
/
Search
g h
Go to the home page
g q
Go to the questions
g t
Go to the tags
g u
Go to the users
a
Ask a question

Lists of questions

j k
Next or previous question
Enter
Open the question

Question pages

j k
Next or previous post

Shortcuts never apply while you type in a text field. Members can turn them off in their preferences.