Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

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

For example, we have a Rest Service with two request parameters: firstName and lastName. To merge their values you should create the following mapping: map firstName to localStorage variable "firstName", and lastName to Label component.
Image

In the line with Label component click "Add JS" and paste the following code:
codevar fullName = localStorage.firstName + " " + value;
return fullName;/code
So, in Label will be displayed response parameter firstName and lastName separated by space.

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

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

oh, very good example. Now, next question: 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?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

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

In element variable, there is stored HTML component where mapping is set to. It may be label, button, grid, etc.

w
Posts: 0
Joined: Tue Mar 26, 2013 12:30 pm

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

That's a good solution for 2 response values, but what if I have 10 response values that I have to combine into 1 label?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

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

Hi,

You can implement this using JavaScript. For example, you can save values to local storage variables and then combine their values into Label component text.

w
Posts: 0
Joined: Tue Mar 26, 2013 12:30 pm

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

How exactly? Mapping multiple response fields to one UI field is easy if the UI field is a static standalone field.
How to do it if the response consists of an array of 10 fields, which you want to convert to a grid, which will dynamically have 1 row for each of the array-items of the response, but the grid contains only 1 label that needs the 10 fields combined.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

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

I'll look for a solution and update.

Oleg Danchenkov
Posts: 0
Joined: Tue Apr 30, 2013 5:51 pm

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

It is difficult to say in your particular case.
I'll give you an example. Hope this will help.
For example you have this JSON in response
precode[
{
"data": "some text1",
"values": ["f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10"]
},
{
"data": "some text2",
"values": ["n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9", "n10"]
}
]
/code/pre
Response will looks like this
Image
You want to map all values from "values" to label in grid cell
Image
Add mapping
Image
In JS in mapping from $ to mobilegrid_4 add this code
precodevar valuesArray = value["values"];
$('[dsid=valuesLabel]', element).text(valuesArray.join(", "));
/code/pre

RobertJay
Posts: 0
Joined: Fri Jun 15, 2012 1:32 pm

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

What is the tree order determined by (the database column?) assuming it cannot be adjusted in the UI.

Return to “Issues”