Quick tip on using JSON data resources & sharing records between apps.

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...

  1. map model.getCientInfo(int id)
  2. {
  3.     //test with 430627000001137700
  4.     r = map();
  5.     data = map();
  6.     r.put("status", "failed");
  7.     r.put("message", "Either the client request failed or we were unable to locate the client's record");
  8.      r.put("data",data.toString());
  9.     url = "http://creatorexport.zoho.com/adminuser/appname/json/template_resource/";
  10.     url = url + "public_string234242342323/";
  11.     url = url + "ID=" + input.id;
  12.     res = getUrl(url,false);
  13.     code = res.get("responseCode");
  14.     text = res.get("responseText");
  15.     if (code  ==  "200")
  16.     {
  17.       //HEY LOOK NO XML! JUST STRAIGHT UP JSON TO MAP!
  18.         data = text.toMap();
  19.         r.put("status","OK");
  20.         r.put("message","client record found and converted");
  21.         r.put("data",data.toString());
  22.     }
  23.     return r;
  24. }
Another great benefit of using this format is that it's cross account friendly! 
  

    Access your files securely from anywhere







                            Zoho Developer Community




                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                  • Ask the Experts





                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator Resources



                                                                                      Zoho CRM Resources

                                                                                      • CRM Community Learning Series

                                                                                        CRM Community Learning Series


                                                                                      • Kaizen

                                                                                        Kaizen

                                                                                      • Functions

                                                                                        Functions

                                                                                      • Meetups

                                                                                        Meetups

                                                                                      • Kbase

                                                                                        Kbase

                                                                                      • Resources

                                                                                        Resources

                                                                                      • Digest

                                                                                        Digest

                                                                                      • CRM Marketplace

                                                                                        CRM Marketplace

                                                                                      • MVP Corner

                                                                                        MVP Corner









                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now


                                                                                            Zoho Show Resources

                                                                                              Zoho Writer

                                                                                              Get Started. Write Away!

                                                                                              Writer is a powerful online word processor, designed for collaborative work.

                                                                                                Zoho CRM コンテンツ



                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方