Wednesday, 6 January 2016

Invoking a REST service in Oracle BPM/PCS webform

One of the common requirement in oracle BPM/PCS webforms is to populate the dropdowns by calling a REST service. Below java script code shows populating the dropdown values by calling the REST service.

This code assumes the rest service returns list of items which is name/value pair.
/*member count, items*/
/*member id */
var x;
if (form.load)
{

   Status.value = 'No errors';
   try {
      var uri = "REST_SERVICE_URL";
      eval('x=' + http.get(uri));

      }  catch (e) {
        Status.value = 'got exception' + e ;
   }
   var lovArray = [];
   for (var i=0; i< x.items.length; i++)
   {
      lovArray[i]=x.items[i].name;

   }

   DepartmentsList.options = lovArray;

}

This code assumes the rest service returns just list of values which needs to be displayed in dropdown

/* member items, id */
if(DepartmentsList.value.length>0)
{
  
  try {

      var uri = 'REST_SERVICE_URL;
      eval('x=' + http.get(uri));

      }  catch (e) {
        Status.value =  uri + e;
   }
   approverList.options =x;

}