Page 2 of 3

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

Posted: Tue Mar 26, 2013 8:38 pm
by Kateryna Grynko

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.


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

Posted: Tue Mar 26, 2013 8:58 pm
by Martin Davis

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?


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

Posted: Tue Mar 26, 2013 9:04 pm
by Kateryna Grynko

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


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

Posted: Tue Mar 26, 2013 9:36 pm
by Kateryna Grynko

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

Posted: Thu May 02, 2013 9:54 am
by w

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?


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

Posted: Thu May 02, 2013 11:16 am
by Kateryna Grynko

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.


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

Posted: Thu May 02, 2013 11:31 am
by w

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.


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

Posted: Thu May 02, 2013 11:53 am
by Kateryna Grynko

I'll look for a solution and update.


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

Posted: Tue May 07, 2013 10:15 am
by Oleg Danchenkov

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


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

Posted: Mon May 12, 2014 8:02 pm
by RobertJay

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