Page 1 of 1

Conditional Mapping with array of values returned from a service

Posted: Sun Nov 20, 2016 9:49 pm
by Todd Penny6646042

Hello,

I need some help getting conditional mapping to work for an array of values returned by a service. The logic is like this:

if (value1(i) == "") then return value2(i)

value1 is the data field that's mapped, value 2 is another field which is also returned from the service. Note these are an array.

I have attached a couple of pictures that show the exact situation.

Image Image


Conditional Mapping with array of values returned from a service

Posted: Mon Nov 21, 2016 5:11 am
by Logan

Hi Penny.

Do you want to check that condition for each record which coming from array?

Logan.


Conditional Mapping with array of values returned from a service

Posted: Mon Nov 21, 2016 8:38 am
by Todd Penny6646042

Yes, I want to display either Value1 or Value2 for each row of data depending on whether Value1 is blank or not.


Conditional Mapping with array of values returned from a service

Posted: Mon Nov 21, 2016 9:19 am
by Logan

Hi Penny.

Do the following things:

First from the response of service bind array with list component's text property and write the following js code.

var value1 = JSON.stringify(assestTypeName);
var value2 = JSON.stringify(otherType);

// check the condition

if(value1 === ""){
Apperyio('resultListItem').text(value2);
}else{
Apperyio('resultListItem').text(value1);
}

Logan.


Conditional Mapping with array of values returned from a service

Posted: Mon Nov 21, 2016 1:50 pm
by Todd Penny6646042

Thanks for your help. I added this mapping code per the attached screen shot and the results are the same. There is no mapping. Any ideas?
Image


Conditional Mapping with array of values returned from a service

Posted: Mon Nov 21, 2016 4:22 pm
by Todd Penny6646042

I checked the error log and this is what I see. It looks like the two variables are not coming through the mapping correctly.

User transformation function exception. Reason: otherType is not defined


Conditional Mapping with array of values returned from a service

Posted: Mon Nov 21, 2016 7:40 pm
by Serhii Kulibaba

Hello Todd,

Please use a mapping arrow $-resultListItem instead of: assetTypeName - resultListItem:
Image
And use here JS code below:
prereturn value.assetTypeName || value.otherType;/pre


Conditional Mapping with array of values returned from a service

Posted: Mon Nov 21, 2016 8:28 pm
by Todd Penny6646042

That worked! You can see our app in action here, we use your service for our app!
GoCodes Asset Tracking