How to load a collection with a default value for a number format ?

413 views
Skip to first unread message

yves.deveyrac@etrali;com

unread,
Mar 23, 2015, 12:23:11 PM3/23/15
to suppor...@runmyprocess.com
Hello,

I use the following script to load a collection.

<#assign my_object>
{
« field_1":"${text_variable_1?default("")}",
"field_2": ${number_variable?default("")}
}
</#assign>
${save_object(my_object,"collection_name")}

When the value of the variable is not defined / empty, the script works fine for fiedl_1 but not for field_2. The error is ‘JSONException: Malformed object’.
If I use "field_2":${number_variable?default("") ?number}, the error is ‘Expecting a number here, found: ‘.

What is the correct script so that an empty variable doesn’t create an error when loading a number in a collection ?

Regards
Yves

Pray Desai

unread,
Mar 23, 2015, 2:09:55 PM3/23/15
to suppor...@runmyprocess.com, yves.d...@gmail.com

Hello Yves,

" " indicates empty string. So if you want to keep default number then you can write 0 

 "field_2": ${number_variable?default(0)} 


Regards,
Pray Desai,
Fujitsu RunMyProcess.

yves.d...@gmail.com

unread,
Mar 23, 2015, 3:26:20 PM3/23/15
to suppor...@runmyprocess.com, yves.d...@gmail.com
Thanks Pray for your quick response.
I did try this solution and I tried it again : still got the same error ‘JSONException: Malformed object’
If I test the followng code in the test area :
<#assign my_object>
{
"field_2": ${number_variable?default(7)}
}
</#assign>
${my_object}

and enter no data for the number_variable, it prints :

{
"field_2":
}
So it looks like the ?default(7) is not triggered

Regards
Yves

Pray Desai

unread,
Mar 23, 2015, 4:02:39 PM3/23/15
to suppor...@runmyprocess.com, yves.d...@gmail.com
Hi Yves,

Inorder to test this, you dont need to pass the numberic variable at all from test console. If you enter no data for numeric variable from test console, then it accepts as empty string and so your default 7 script does not execute. 

See below screenshot that returned 7 when there this variable was not defined.

Inline image 1

Regards,
Pray Desai,
Fujitsu RunMyProcess.


Regards
Yves

--
Fujitsu - RunMyProcess
---
You received this message because you are subscribed to the Google Groups "Fujitsu RunMyProcess Developer Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supportforum...@runmyprocess.com.
To post to this group, send email to suppor...@runmyprocess.com.
Visit this group at http://groups.google.com/a/runmyprocess.com/group/supportforum/.
To view this discussion on the web visit https://groups.google.com/a/runmyprocess.com/d/msgid/supportforum/c2fe0338-a2dc-4903-8435-3515f9479f41%40runmyprocess.com.

yves.d...@gmail.com

unread,
Mar 24, 2015, 4:57:18 AM3/24/15
to suppor...@runmyprocess.com, yves.d...@gmail.com
It works. Merci Pray

Regards
Yves
Reply all
Reply to author
Forward
0 new messages