Part 3 – Invoking PCS Process from Oracle JET Framework

Part 3 – Invoking PCS Process from Oracle JET Framework

REST URL: PCS Allows various rest URLS for various tasks such as Creating a Process Task, View Task Details and various other Services , the most important thing is to understand the URLs and how to call them, You can download Advanced REST Client or Postman Tool that comes as a part of chrome browser plugin

The REST URL will be

https://pcsname-idmdomainname.process.us2.oraclecloud.com/bpm/api/4.0/processes

Select Basic Authentication , Give username and password that you login to PCS Instance with Admin Privileges, Update request and Send GET request

JSON Response will be as shown below

{
    "count": 1,
    "hasMore": false,
    "items": [
        {
            "levels": 0,
            "title": "Instance #260302 of OSCA_Travel_Approval_Process",
            "processId": "260302",
            "processName": "OSCATravelApprovalProcess",
            "priority": 0,
            "ownedBy": "OSCA_Processes.ProcessOwner",
            "createdBy": "softwarearchitect73@gmail.com",
            "state": "OPEN",
            "createdDate": "2017-07-05T15:24:15.000Z",
            "processDN": "default~OSCA_Processes!1.2~OSCATravelApprovalProcess",
            "processNumber": 371338,
            "href": "https://somepcsurl:443/bpm/api/4.0/processes/260302"
        }
    ],
    "links": [
        {
            "href": "https://somepcsurl:443/bpm/api/4.0/",
            "length": 0,
            "rel": "parent"
        },
        {
            "href": "https://somepcsurl:443/bpm/api/4.0/
processesueDateTo=&processDefId=&orderBy=", "length": 0, "rel": "self" } ], "totalResults": 1 }

The detailed document on PCS REST is here

let us now see how to Invoke this Process from a Java Script Driven Oracle JET Application

define(['ojs/ojcore', 'knockout', 'toastr', 'ojs/ojknockout-validation', 'ojs/ojknockout', 'ojs/ojmodel', 
    'ojs/ojbutton', 'ojs/ojinputtext', 'ojs/ojinputnumber',  'ojs/ojdatetimepicker', 
    'ojs/ojselectcombobox'], 
function (oj, ko,  toastr) { 
    function travelContentViewModel() {
        var self = this;
        self.serviceURL = 'https://pcsurl.oraclecloud.com/bpm/api/4.0/processes';
        self.locationModel = ko.observable();
        self.list = ko.observable();
        self.tracker = ko.observable();
        self.managers = ko.observableArray();
        self.selectedManager = ko.observableArray(); 
        self.country = ko.observable(); 
        self.eventDate = ko.observable();
        self.eventDate2 = ko.observable();
         toastr.options = {
                "closeButton": true,
                "debug": false,
                "newestOnTop": false,
                "progressBar": true,
                "positionClass": "toast-top-center",
                "preventDuplicates": false,
                "onclick": null,
                "showDuration": "300",
                "hideDuration": "1000",
                "timeOut": "5000",
                "extendedTimeOut": "1000",
                "showEasing": "swing",
                "hideEasing": "linear",
                "showMethod": "fadeIn",
                "hideMethod": "fadeOut"
              } 
        
        self.dateConverter = ko.observable(oj.Validation.
converterFactory(oj.ConverterFactory.CONVERTER_TYPE_DATETIME). createConverter( { pattern: 'dd-MMM-yyyy' })); self.convertServerDate = function(serverDate){ if(serverDate != null){ var parts = serverDate.split('/'); var month; switch(parts[1]){ case "01": month = "Jan"; break; case "02": month = "Feb"; break; case "03": month = "Mar"; break; case "04": month = "Apr"; break; case "05": month = "May"; break; case "06": month = "Jun"; break; case "07": month = "Jul"; break; case "08": month = "Aug"; break; case "09": month = "Sep"; break; case "10": month = "Oct"; break; case "11": month = "Nov"; break; case "12": month = "Dec"; break; default: break; } var formatedDate = parts[0]+"-"+month+"-"+parts[2]; return formatedDate; } return ""; }; self.duration = ko.observable(); self.duration2 = ko.observable(); self.duration3 = ko.observable(); this.duration3 = ko.computed(function () { return Number(this.duration()) + Number(this.duration2() )}, this); $.getJSON(self.serviceURL, function(people){ for(var i=0; i<people.items.length; i++) { var item = people.items[i]; self.managers.push({value: item.person_id,
label: item.firstname + ' '+ item.lastname}); } }); self._showComponentValidationErrors = function (trackerObj) { trackerObj.showMessages(); var hasInvalidComponents = trackerObj ? trackerObj["invalidShown"] : false; if (trackerObj.focusOnFirstInvalid() && hasInvalidComponents) return false; return true; }; self.goBack = function() { oj.Router.rootInstance.store(null); oj.Router.rootInstance.go("addTravel"); };

 On Submit Button Invoke Save Travel Method, Params will actually Pass Message Parameters from JET Form Submission to Process in Process Cloud Service

        self.saveTravel = function() {            
                var trackerObj = ko.utils.unwrapObservable(self.tracker); 
                if (!this._showComponentValidationErrors(trackerObj))
                {
                  return;
                }
                else{
                    var r = confirm("Please Confirm to Submit Travel Approval Request ?");
                    if (r == true) {
                        var personData = 
                            {                                
                                "processDefId": "default~OSCA_Processes!1.2~OSCATravelApprovalProcess",
                                "serviceName": "OSCATravelApprovalProcess.service",
                                "operation": "start",
                                "action": "Submit", 
                                "params":  
                                        {
                                            "msgIn_firstname":$("#firstname").val(), 
                                            "msgIn_lastname":$("#lastname").val(),
                                            "msgIn_travelfrom":$("#travelfrom").val(),
                                            "msgIn_travelto":$("#travelto").val(),
                                            "msgIn_traveleremail":$("#traveleremail").val(),
                                            "msgIn_traveldate":$("#traveldate").val(),
                                            "msgIn_travelcost":$("#travelcost").val(),
                                            "msgIn_traveljustification":$("#traveljustification").val(),
                                            "msgIn_traveltype":$("#traveltype").val(),
                                            "msgIn_travelerorg":$("#travelerorg").val(),
                                            "msgIn_approveremail":$("#approveremail").val(),
                                            "msgIn_travelcostflight":$("#travelcostflight").val(),
                                            "msgIn_traveldateto":$("#traveldateto").val() 
                                      }
                            };

                        console.log("Travel Data is " + JSON.stringify(personData)); 
                         $.ajax({
                            type: "POST",
                            url: self.serviceURL,
                            headers: {"Authorization": "Basic " + btoa("pcsusername:pcspassword")},
                            data: JSON.stringify(personData),
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            processData: true,
                            success: function (data, status, jqXHR){
                                console.log("success..." + data); 
// On Success - Show Success Message on Browser toastr.success("Successfully Travel Request Submitted ! "); oj.Router.rootInstance.store(null);
// Redirect Back to Travel Application Form Screen oj.Router.rootInstance.go("viewTravel"); }, error: function (xhr) { console.log(xhr.responseText);
// On Error - Show Error Message on Browser toastr.error("Error in Travel Approval Submission , please contain"); oj.Router.rootInstance.store(null); oj.Router.rootInstance.go("travel"); } }); } } }; } return travelContentViewModel; });

Demo PCS Travel App with Email Approval of Task

Mobile Approval of Task

<< Part 2 – How to Build Process , Data Persistence in Database Cloud Service