Page 1 of 3

How can I combine two REST service response values in one label?

Posted: Thu Jun 21, 2012 3:57 pm
by ghuisintveld

I have a rest service that returns two values: year and month. I would like to combine those two in one label, so that the label text lookes like "January, 2012".

Is it possible to combine two values or do I have to create two labels to achieve this? If so, how can I make the width of the labels "auto"? If I try this, I keep ending up with the two values on two seperate lines.


How can I combine two REST service response values in one label?

Posted: Thu Jun 21, 2012 4:48 pm
by maxkatz

Map both of them, make one of the labels invisible (year in this example). Then for the component where you want to display the result, run this JavaScript:

code
var year = Tiggzi('year').text();
return value+" "+year;
/code


How can I combine two REST service response values in one label?

Posted: Thu Sep 13, 2012 7:16 pm
by KAGO_DK

Are you able to provide an example, because I am also trying to combine two values into one label (in a grid)? It is bit unclear where I should store your javascript and how/if it should be triggered by an event.


How can I combine two REST service response values in one label?

Posted: Thu Sep 13, 2012 8:40 pm
by maxkatz

Let's say you have two UI components named 'year' and 'month'.

First, you map these values as usual.

For 'month', open JavaScript editor and write this:

var year = Tiggzi('year').text();
return value+" "+year;

the first line gets a value from the 'year' component. As you are in the mapping for 'month', its value is passed as 'value'. Now you can combine the two values.

The only think to keep in mind is order matters. In other words, 'year' should be before 'month' in the tree.


How can I combine two REST service response values in one label?

Posted: Fri Sep 14, 2012 2:32 am
by KAGO_DK

Image

Is this correct understood?


How can I combine two REST service response values in one label?

Posted: Fri Sep 14, 2012 3:37 am
by maxkatz

Yes.


How can I combine two REST service response values in one label?

Posted: Fri Oct 19, 2012 7:36 pm
by egonzalez

Hi Max, I've tried the example and it doesn't seem to work. I've tried changing the order as well with no luck. Image

I need some help please.


How can I combine two REST service response values in one label?

Posted: Sat Oct 20, 2012 12:36 am
by maxkatz

Sorry, I guess I was thinking about something else but the solution I provided won't work.

I think this should work. Map both variables to a component on a page. The first component, make it invisible, and save its value in local storage. Then, in the second mapping, get the value from local storage and combine the two.


How can I combine two REST service response values in one label?

Posted: Tue Mar 26, 2013 5:57 pm
by Martin Davis

When you are adding JS to a response and it opens up the "function(value, element) {.....}" box, could you explain what "element" is referring to?


How can I combine two REST service response values in one label?

Posted: Tue Mar 26, 2013 5:59 pm
by Martin Davis

Could you provide the code and appropriate screenshots to explain this answer, particularly what code goes where?