Todd Penny6646042
Posts: 0
Joined: Fri Feb 07, 2014 10:52 pm

Conditional Mapping with array of values returned from a service

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

Logan
Posts: 0
Joined: Tue Sep 20, 2016 11:26 am

Conditional Mapping with array of values returned from a service

Hi Penny.

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

Logan.

Todd Penny6646042
Posts: 0
Joined: Fri Feb 07, 2014 10:52 pm

Conditional Mapping with array of values returned from a service

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

Logan
Posts: 0
Joined: Tue Sep 20, 2016 11:26 am

Conditional Mapping with array of values returned from a service

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.

Todd Penny6646042
Posts: 0
Joined: Fri Feb 07, 2014 10:52 pm

Conditional Mapping with array of values returned from a service

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

Todd Penny6646042
Posts: 0
Joined: Fri Feb 07, 2014 10:52 pm

Conditional Mapping with array of values returned from a service

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

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Conditional Mapping with array of values returned from a service

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

Todd Penny6646042
Posts: 0
Joined: Fri Feb 07, 2014 10:52 pm

Conditional Mapping with array of values returned from a service

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

Return to “Issues”