Author Topic: Consuming an OData service using Liquid UI  (Read 5929 times)

Rahul Gera

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 88
    • View Profile
Consuming an OData service using Liquid UI
« on: January 11, 2019, 04:24:17 PM »
Purpose: To consume an OData service and to display the result in a Liquid UI table.

Pre-Requisites:
1. Specify the URL
2. Load wscurl library  load('wscurl');

Liquid UI Script:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// Use Curl to retrieve oData response /////////////////////////////////////////////////
////////////// Display Result using Liquid UI Table  (table, and column commands) ///////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


clearscreen();

title('Consuming oData Service');
box([1,1],[18,102],'Consuming oData Service');
z_oData_Service = "https://services.odata.org/V4/Northwind/Northwind.svc/Customers";
inputfield([2,2], "oData Service", [2,20],  {"name":"z_oData_Service", "size":80,"readonly":true});

var custObj = odata_GetCustomers();

// Display customer table
table([4,3],[17,101], {"title":"Northwind Customers","name":"tbl_customers","rows":custObj.value.length});
column("Company",{"size":40,"name":"z_company","readonly":true});
column("City",{"size":30,"name":"z_city","readonly":true});
column("Country",{"size":20,"name":"z_country","readonly":true});

for (var j = 0; j < custObj.value.length; j++) {
   var c = custObj.value[j];
   tbl_customers.z_company[j] = unescape(encodeURI(c.CompanyName));
   tbl_customers.z_city[j] = unescape(encodeURI(c.City));
   tbl_customers.z_country[j] = unescape(encodeURI(c.Country));
   
};


function odata_GetCustomers() {
   
   var wsCurl = new Curl();
   var baseURL = encodeURI("https://services.odata.org/V4/Northwind/Northwind.svc/Customers");
    wsCurl.setopt(Curl.CURLOPT_URL, baseURL);
   wsCurl.setopt(Curl.CURLOPT_HEADER,0);
    wsCurl.setopt(Curl.CURLOPT_VERBOSE,1);
   var response = wsCurl.exec();
   wsCurl.close();

   /* Remove any reference for Garbage Collection*/
   wsCurl= NULL;
   response = eval("(" + response + ")");
   return response;
}
« Last Edit: January 11, 2019, 05:05:02 PM by Rahul Gera »