Page 1 of 1

Testing rest service response value with javascript

Posted: Fri Feb 15, 2013 5:44 pm
by Sean Kelley

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;
}


Testing rest service response value with javascript

Posted: Fri Feb 15, 2013 8:51 pm
by maxkatz

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


Testing rest service response value with javascript

Posted: Fri Feb 15, 2013 9:20 pm
by Sean Kelley

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'


Testing rest service response value with javascript

Posted: Fri Feb 15, 2013 9:28 pm
by maxkatz

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


Testing rest service response value with javascript

Posted: Fri Feb 15, 2013 10:43 pm
by Sean Kelley

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.


Testing rest service response value with javascript

Posted: Sat Feb 16, 2013 5:26 am
by maxkatz

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.


Testing rest service response value with javascript

Posted: Sat Feb 16, 2013 12:01 pm
by Sean Kelley

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