Quick tip on using JSON data resources & sharing records between apps.
Howdy,
Just thought I would bring this to your attention. If you don't know this already when you make a getURL/postURL request to a JSON resource Zoho allows you to convert that JSON to XML using toXML(). BUT, did you know that you can convert it straight to a map var? This is especially useful when you just want to grab one single JSON record to populate an html page or form.
Example :
Let's say that you want to grab a SINGLE record out of a separate app in the same account. The traditional way of programmatically sharing information between to ZC apps is by writing an accessor function in the app HOLDING the desired record and then calling this function from the other app to get the record's fields.
PROBLEM WITH THIS WAY!
Annoyingly, Zoho Creator doesn't allow you to send over a record pointer, I mean you can't return a collection variable of course! So one must resort to putting the fields you want to return into a map. This is verbose and hard to maintain as you add more fields to the HOLDING app form.
BETTER WAY..
Make a getURL call to the JSON resource for the HOLDING app's view like this...
- map model.getCientInfo(int id)
- {
- //test with 430627000001137700
- r = map();
- data = map();
- r.put("status", "failed");
- r.put("message", "Either the client request failed or we were unable to locate the client's record");
- r.put("data",data.toString());
- url = "http://creatorexport.zoho.com/adminuser/appname/json/template_resource/";
- url = url + "public_string234242342323/";
- url = url + "ID=" + input.id;
- res = getUrl(url,false);
- code = res.get("responseCode");
- text = res.get("responseText");
- if (code == "200")
- {
- //HEY LOOK NO XML! JUST STRAIGHT UP JSON TO MAP!
- data = text.toMap();
- r.put("status","OK");
- r.put("message","client record found and converted");
- r.put("data",data.toString());
- }
- return r;
- }
Another great benefit of using this format is that it's cross account friendly!