ghuisintveld
Posts: 0
Joined: Fri Jun 08, 2012 11:29 am

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

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

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

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

KAGO_DK
Posts: 0
Joined: Thu Sep 13, 2012 7:16 pm

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

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

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

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.

KAGO_DK
Posts: 0
Joined: Thu Sep 13, 2012 7:16 pm

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

Image

Is this correct understood?

egonzalez
Posts: 0
Joined: Fri Sep 14, 2012 9:34 pm

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

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

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

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.

Martin Davis
Posts: 0
Joined: Mon Mar 18, 2013 5:31 pm

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

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?

Martin Davis
Posts: 0
Joined: Mon Mar 18, 2013 5:31 pm

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

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

Return to “Issues”