cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
915
Views
5
Helpful
2
Replies

Set UCCX Currency variable

btrain1227
Level 1
Level 1

Hello,

 

I'm still rather new to UCCX and Java. I retrieve some info from a REST call and end up with a currency designator in a string variable. 

 

curCode = "EUR"

 

How can I create a Currency variable from this string value?

 

Thanks,

 

Brad

1 Accepted Solution

Accepted Solutions

Anthony Holloway
Cisco Employee
Cisco Employee

 

Welcome to the world of UCCX!

 

Please use this forum as much as possible, whenever you have questions.  We have a small group of volunteers, both external to Cisco (such as myself), and internal to Cisco who selflessly give their time to read, think about, and respond to user submitted questions.  We often times re-create scenarios in our own labs to prove or disprove a solution, and this takes time, but we all really enjoy the process.

 

If you do start to get to the point where you find that you no longer need to ask questions on the forums, perhaps you could start to transition to answering questions.  I think you'll find that even though you have made that transition to contributor, you'll continue to grow in your career and knowledge, because other's will continually challenge you with questions and scenarios you've never encountered.  For example, this is the exact situation I find myself in with your question.

 

The first thing I should let you know is, the Set step will do an amazing job at converting between data types.  E.g.,  You have a String literal like "36" and you have an int variable called age.  Simply using:

 

Set age = "36"

 

Will convert the String literal into an int and store it in the variable age for you.  In Java you might have to use:

 

Set age = (int) "36"

 

And that can be done in the Set step too, but it's unnecessary. because the Set step is doing that for you.  It's not always going to be so easy though, so keep a sharp eye out for when it fails you (wink wink).

 

According to the Expression Language Reference 11.0, Page 3-37, we can create Currency objects like this:

 

C[CurrencyDesignator]

 

However, unlike the Prompt literal, where you could supply an Expression inside the brackets, and the expression will be evaluated to find the resulting prompt name, you must provide the literal value for CurrencyDesignator.

 

E.g., Prompt Literals and Expressions

 

UserPromptDeclarator [Expression]

 

If the sequence of characters can be parsed as an Expression of type String, then the resulting prompt
is a user prompt where the expression specifies the name of the prompt to retrieve the prompt from
the repository

 

Source: Expression Language Reference 11.0, Page 3-99

 

So, we couldn't simply do:

 

Set desired_currency = "USD"
Set the_currency = C[desired_currency]

 

Because the Currency literal does not accept an expression inside the brackets.  This is a shame really, and I think an over sight on Cisco's part.

 

Ok, so what about what I mentioned earlier with type casting using the Set step then?

 

Set the_currency = desired_currency

 

This fails with the error:

 

Value Semantic Error

Unable to parse expression; unassignable type: String; expecting Currency

 

That's also a shame, and an oversight on Cisco's part, IMO.  Ok, so what about the Java way?

 

Set the_currency = (Currency) desired_currency

 

Well, this fails with the error:

 

Value Lexical Error

Unable to parse expression; invalid type cast from java.lang.String to com.cisco.util.Currency

 

Shame....   Ok, so last trick, and spoiler alert, the one that works.  If you open the Expression Editor (Expression Language Reference v11.0 Page 2-1), and select the Java tab, then in the box where it says "Object Constructors" you highlight (with your mouse) the word "Object" and type (with your keyboard...ok that was obvious) "Curency" so that it reads "Currency Constructors" and then press TAB, you might notice the size of this box change.

 

Now, using your mouse (I don't know why I keep specifying "how"), use the drop down in this box to find that there is only a single Constructor:

 

new Currency(String)

 

Oh boy, here we go.  Ok, so now we know we can construct/create a new Currency object using our String.  So, now we have our Set step looking like this:

 

Set the_currency =  new Currency(desired_currency)

 

And with that, you have your answer, and I now know how to do it too.  So we both win.

View solution in original post

2 Replies 2

Anthony Holloway
Cisco Employee
Cisco Employee

 

Welcome to the world of UCCX!

 

Please use this forum as much as possible, whenever you have questions.  We have a small group of volunteers, both external to Cisco (such as myself), and internal to Cisco who selflessly give their time to read, think about, and respond to user submitted questions.  We often times re-create scenarios in our own labs to prove or disprove a solution, and this takes time, but we all really enjoy the process.

 

If you do start to get to the point where you find that you no longer need to ask questions on the forums, perhaps you could start to transition to answering questions.  I think you'll find that even though you have made that transition to contributor, you'll continue to grow in your career and knowledge, because other's will continually challenge you with questions and scenarios you've never encountered.  For example, this is the exact situation I find myself in with your question.

 

The first thing I should let you know is, the Set step will do an amazing job at converting between data types.  E.g.,  You have a String literal like "36" and you have an int variable called age.  Simply using:

 

Set age = "36"

 

Will convert the String literal into an int and store it in the variable age for you.  In Java you might have to use:

 

Set age = (int) "36"

 

And that can be done in the Set step too, but it's unnecessary. because the Set step is doing that for you.  It's not always going to be so easy though, so keep a sharp eye out for when it fails you (wink wink).

 

According to the Expression Language Reference 11.0, Page 3-37, we can create Currency objects like this:

 

C[CurrencyDesignator]

 

However, unlike the Prompt literal, where you could supply an Expression inside the brackets, and the expression will be evaluated to find the resulting prompt name, you must provide the literal value for CurrencyDesignator.

 

E.g., Prompt Literals and Expressions

 

UserPromptDeclarator [Expression]

 

If the sequence of characters can be parsed as an Expression of type String, then the resulting prompt
is a user prompt where the expression specifies the name of the prompt to retrieve the prompt from
the repository

 

Source: Expression Language Reference 11.0, Page 3-99

 

So, we couldn't simply do:

 

Set desired_currency = "USD"
Set the_currency = C[desired_currency]

 

Because the Currency literal does not accept an expression inside the brackets.  This is a shame really, and I think an over sight on Cisco's part.

 

Ok, so what about what I mentioned earlier with type casting using the Set step then?

 

Set the_currency = desired_currency

 

This fails with the error:

 

Value Semantic Error

Unable to parse expression; unassignable type: String; expecting Currency

 

That's also a shame, and an oversight on Cisco's part, IMO.  Ok, so what about the Java way?

 

Set the_currency = (Currency) desired_currency

 

Well, this fails with the error:

 

Value Lexical Error

Unable to parse expression; invalid type cast from java.lang.String to com.cisco.util.Currency

 

Shame....   Ok, so last trick, and spoiler alert, the one that works.  If you open the Expression Editor (Expression Language Reference v11.0 Page 2-1), and select the Java tab, then in the box where it says "Object Constructors" you highlight (with your mouse) the word "Object" and type (with your keyboard...ok that was obvious) "Curency" so that it reads "Currency Constructors" and then press TAB, you might notice the size of this box change.

 

Now, using your mouse (I don't know why I keep specifying "how"), use the drop down in this box to find that there is only a single Constructor:

 

new Currency(String)

 

Oh boy, here we go.  Ok, so now we know we can construct/create a new Currency object using our String.  So, now we have our Set step looking like this:

 

Set the_currency =  new Currency(desired_currency)

 

And with that, you have your answer, and I now know how to do it too.  So we both win.

Thanks Anthony! I've found your posts to be extremely helpful as I muddle my way through the world of UCCX!