Sean Kelley
Posts: 0
Joined: Thu Oct 11, 2012 2:25 pm

Testing rest service response value with javascript

I am trying to test the response item's value for my image Asset in mapping. I would like to pass along another value to the UI if value='None'. If the value is something other than None I want asset to use the url in the database.
Here is my script. it works to test for None but I do not know how to edit the value that gets passed along to the UI when the value is None. (BTW- I am javascript challenged):

var photo;
if (JSON.photo1=='None'){
src='http://www.mysite.com/logo.jpg';
return src;
}

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

Testing rest service response value with javascript

Can you clarify what value and where you would like to modify?

Sean Kelley
Posts: 0
Joined: Thu Oct 11, 2012 2:25 pm

Testing rest service response value with javascript

I have a database value which is a url to an image. sometimes the value is not good...it is = 'None'. The photo1 database field maps to a UI asset (displaying photo) which works fine if its not None. If it is None, I would like to change the value before it gets mapped so that another image url is used to display a good image.
Hope that makes sense :-)

Incidentally, I am very new to javascript and tggzi but I was thinking that another way to achieve my objective to hide bad images (instead of load dummy ones like I am trying to do in this case) might be to hide the UI image that this is mapped to if it is 'None'. I am not sure how one would do that either. My initial thought might be a javascript event on page load which hides the image with the url='None'

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

Testing rest service response value with javascript

One options is to show a place holder for an image. For example, in mapping for image asset you could write something like this:

code
if (JSON.photo1=='None'){
return "http://somefakeimageurl...&quot
}
else {
return value;
}
/code

Or, hide the image, you could do this:

code
if (JSON.photo1=='None'){
element.parent().hide();
}
/code

Sean Kelley
Posts: 0
Joined: Thu Oct 11, 2012 2:25 pm

Testing rest service response value with javascript

Hmmm...I am unable get get either one of these js (placed via the JS button) on the right of the response item to work for me. (under Component-horsePreview-Asset

When I test my app, I still get a broken image on some listed items. When I right click on chrome browser to inspect item I get:
< Image id="j_25_1" dsid="horsePreview" name="horsePreview" idx="1"

which shows src=" None " the case I am trying to test for.

I assumed that the script to hide may be placed as a on load of page event but I tried it on the response as well.

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

Testing rest service response value with javascript

Where do you get the data from? Is that a list you get back from a service? I was assuming you would run this JavaScript during mapping, from service to page.

Sean Kelley
Posts: 0
Joined: Thu Oct 11, 2012 2:25 pm

Testing rest service response value with javascript

Thanks for your help and sticking with me. I just realized that my original assumption that the test was working was not. A little sleep goes a long way :-)

I thought this was working:
if (JSON.photo1=='None')
but it was not. This did work:
if (value==' None ')

So now I understand that I use value to work with result of service

Return to “Issues”