Forums >> Programming >> Proof of Concept (POC) >>
Retrieving the App Data back to your IBM i




Posted:
bvstone

Retrieving the App Data back to your IBM i

 
Retrieving the App Data back to your IBM i

Once a dispatch is done, we need some way to retrieve the information that was stored in the app for the specific dispatch.

The information is available for download manually from the Canvas page under the "Submissions" menu as shown here:

As stated, at this time there really is no way to trigger the download of the data when the dispatch is submitted from the mobil device, so instead we have a manual refresh process we use.  

The manual submission triggers another POST using GETURI to the Canvas site to find any new submissions that are made.  

A sample of the code used is as follows:

     H DFTACTGRP(*NO) BNDDIR('ERPGSDK')
      ****************************************************************
      * Prototypes                                                   *
      ****************************************************************
     D SUBMISSION      PR
     D                              128
     D                             1024
     D SUBMISSION      PI
     D   inKey                      128
     D   outErrorMsg               1024
      ****************************************************************
      /COPY GETURI/QCOPYSRC,GETURICOPY
      /COPY QCOPYSRC,P.APPSTAT
      /COPY qcopysrc,p.pdocxml
      /COPY qcopysrc,p.libl
      ****************************************************************
      * Work Variables
     D xmlFile         s            500a   varying
     D ignoreMe        s              1a
     D GetError        s               n
     D rc              S             10i 0
      ****************************************************************
      /free
       outErrorMsg = ' ';
       #appstat_setStatus(inKey:'Retrieving Submissions...');
       xmlFile = '/tmp/canvassubmissions.xml';
       #pushLib('GETURI');
       EXSR $LoadParms;
       EXSR $GETURI;
       #popLib('GETURI');

       if (not GetError);
         #appstat_setStatus(inKey:'Processing Submissions...');
         rc = #pdocxml_setKey(inKey);
         rc = #pdocxml_setID('submission');
         rc = #pdocxml_clearErrors();
         rc = #pdocxml_loadRefs();
         xml-sax %handler(#pdocxml_xmlHandler:ignoreMe)
              %XML(xmlFile: 'doc=file');
       else;
         outErrorMsg = GetUri_Msg;
       endif;

       *inlr = *on;

       //***************************************************************
       //* Load GETURI Parameters
       //***************************************************************
       BegSr $LoadParms;

         CLEAR GetUri_In;
         GI_URI = 'https://www.gocanvas.com/apiv2/submissions.xml?' +
                  'username=xxxxxxxx&password=xxxxxxxxx&' +
                  'form_name=Dispatch';
         GI_ReqMeth = 'POST';
         GI_SSL   = '*YES';
         GI_Port   = 443;
         GI_CCSID  = 1208;
         GI_CodPag  = 1208;
         GI_OutType   = '*STMF';
         GI_Stmf = xmlFile;
         GI_SprHead = '*YES';
         GI_Debug = '*YES';

       EndSr;
       //***************************************************************
       //* Call GETURI
       //***************************************************************
       BegSr $GETURI;

      /end-free
     C                   CALL      'GETURIRG'                           99
     C                   PARM                    GetUri_In
     C                   PARM                    GetUri_Out
     C                   PARM                    GetUri_Head
     C                   PARM                    GetUri_Data
     C                   PARM                    GetUri_MsgCd
     C                   PARM                    GetUri_Msg
      /free

         GetError = (%scan('200 OK':GetUri_Head) <= 0) or (*IN99);

       EndSr;

      /end-free

The POST looks like the following:

POST /apiv2/submissions.xml?username=xxxxxx&password=xxxxxxx&form_name=Dispatch HTTP/1.0
Accept: text/html
Host: www.gocanvas.com
Content-type: application/x-www-form-urlencoded
Content-length: 0

What this request is doing is saying "retrieve all the data for any submissions with the form name of Dispatch.

The data returned is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<CanvasResult>
 <TotalPages>1</TotalPages><CurrentPage>1</CurrentPage><Submissions><Submission Id="8092165">
  <Form Id="700427">
    <Name>Dispatch</Name>
    <Status>published</Status>
    <Version>14</Version>
  </Form>
  <Date>2014.10.02 18:33:50</Date>
  <DeviceDate>2014.10.02 18:31:12</DeviceDate>
  <UserName>bvstone@bvstools.com</UserName>
  <FirstName>Bradley</FirstName>
  <LastName>Stone</LastName>
  <ResponseID>63fff60953a2c4cf-1412269994795</ResponseID>
  <Sections>
    <Section>
    <Name>Customer Information</Name>
    <Screens>
      <Screen>
      <Name>Customer Information</Name>
            <Responses>
              <Response>
        <Label>ticket_id</Label>
        <Value>41</Value>
        <Type>Integer</Type>
        </Response>
        <Response>
        <Label>order_date</Label>
        <Value>04/17/2014</Value>
        <Type>Date</Type>
        </Response>
        <Response>
        <Label>customer_email</Label>
        <Value>cindysmith@cindy.com</Value>
        <Type>Text Box</Type>
        </Response>
        <Response>
        <Label>customer_business</Label>
        <Value></Value>
        <Type>Text Box</Type>
        </Response>
        <Response>
        <Label>customer_contact</Label>
        <Value>Cindy Smith</Value>
        <Type>Text Box</Type>
        </Response>
        <Response>
        <Label>customer_add1</Label>
        <Value>111 Main Street</Value>
        <Type>Text Box</Type>
        </Response>
        <Response>
        <Label>customer_add2</Label>
        <Value></Value>
        <Type>Text Box</Type>
        </Response>
        <Response>
        <Label>customer_state</Label>
        <Value>AL</Value>
        <Type>Value List</Type>
        </Response>
        <Response>
        <Label>customer_city</Label>
        <Value>Fairhope</Value>
        <Type>Text Box</Type>
        </Response>
        <Response>
        <Label>customer_zip</Label>
        <Value>60004</Value>
        <Type>Text Box</Type>
        </Response>
        <Response>
        <Label>customer_phone</Label>
        <Value>18478705236</Value>
        <Type>Text Box</Type>
        </Response>
            </Responses>
      </Screen>
    </Screens>
    </Section>
    <Section>
    <Name>Description of Work Performed</Name>
    <Screens>
      <Screen>
      <Name>Description of Work Performed</Name>
            <Responses>
              <Response>
        <Label>work_location</Label>
        <Value></Value>
        <Type>Text Box</Type>
        </Response>
        <Response>
        <Label>work_description</Label>
        <Value>install new VOIP phones</Value>
        <Type>Multi-Line Text</Type>
        </Response>
        <Response>
        <Label>work_gps</Label>
        <Value></Value>
        <Type>GPS</Type>
        </Response>
        <Response>
        <Label>default_labor_rate</Label>
        <Value>99.99</Value>
        <Type>Decimal</Type>
        </Response>
        <Response>
        <Label>has_parts</Label>
        <Value>True</Value>
        <Type>Checkbox</Type>
        </Response>
        <Response>
        <Label>has_labor</Label>
        <Value>True</Value>
        <Type>Checkbox</Type>
        </Response>
            </Responses>
      </Screen>
    </Screens>
    </Section>
    <Section>
    <Name>Parts List</Name>
    <Screens>
      <Screen>
      <Name>Parts List</Name>
        <ResponseGroups>
        <ResponseGroup>
          <Response>
          <Label>part_qty</Label>
          <Value>5</Value>
          <Type>Integer</Type>
          </Response>
          <Section>
          <Name>Parts List (Detail)</Name>
          <Screens>
            <Screen>
            <Name>Parts List</Name>
                  <Responses>
                    <Response>
              <Label>part_number</Label>
              <Value>phones</Value>
              <Type>Text Box</Type>
              </Response>
              <Response>
              <Label>part_desc</Label>
              <Value>voip phones</Value>
              <Type>Text Box</Type>
              </Response>
              <Response>
              <Label>part_each</Label>
              <Value></Value>
              <Type>Decimal</Type>
              </Response>
              <Response>
              <Label>part_total</Label>
              <Value>0.00</Value>
              <Type>Calculation</Type>
              </Response>
                  </Responses>
            </Screen>
          </Screens>
          </Section>
        </ResponseGroup>
        <ResponseGroup>
          <Response>
          <Label>part_qty</Label>
          <Value>20</Value>
          <Type>Integer</Type>
          </Response>
          <Section>
          <Name>Parts List (Detail)</Name>
          <Screens>
            <Screen>
            <Name>Parts List</Name>
                  <Responses>
                    <Response>
              <Label>part_number</Label>
              <Value>cable</Value>
              <Type>Text Box</Type>
              </Response>
              <Response>
              <Label>part_desc</Label>
              <Value></Value>
              <Type>Text Box</Type>
              </Response>
              <Response>
              <Label>part_each</Label>
              <Value></Value>
              <Type>Decimal</Type>
              </Response>
              <Response>
              <Label>part_total</Label>
              <Value>0.00</Value>
              <Type>Calculation</Type>
              </Response>
                  </Responses>
            </Screen>
          </Screens>
          </Section>
        </ResponseGroup>
        </ResponseGroups>
      </Screen>
    </Screens>
    </Section>
    <Section>
    <Name>Labor</Name>
    <Screens>
      <Screen>
      <Name>Labor</Name>
        <ResponseGroups>
        </ResponseGroups>
      </Screen>
    </Screens>
    </Section>
    <Section>
    <Name>Contract Totals</Name>
    <Screens>
      <Screen>
      <Name>Contract Totals</Name>
            <Responses>
              <Response>
        <Label>complete_date</Label>
        <Value>10/02/2014</Value>
        <Type>Date</Type>
        </Response>
        <Response>
        <Label>subtotal_parts</Label>
        <Value>0.00</Value>
        <Type>Summary</Type>
        </Response>
        <Response>
        <Label>subtotal_labor</Label>
        <Value>0.00</Value>
        <Type>Summary</Type>
        </Response>
        <Response>
        <Label>subtotal</Label>
        <Value>0.00</Value>
        <Type>Calculation</Type>
        </Response>
        <Response>
        <Label>tax_rate</Label>
        <Value>7</Value>
        <Type>Decimal</Type>
        </Response>
        <Response>
        <Label>total_tax</Label>
        <Value>0.00</Value>
        <Type>Calculation</Type>
        </Response>
        <Response>
        <Label>total_amount</Label>
        <Value>0.00</Value>
        <Type>Calculation</Type>
        </Response>
            </Responses>
      </Screen>
    </Screens>
    </Section>
    <Section>
    <Name>Signature</Name>
    <Screens>
      <Screen>
      <Name>Signature</Name>
            <Responses>
              <Response>
        <Label>Customer Signature</Label>
        <Value>502357631</Value>
        <Type>Signature</Type>
        </Response>
            </Responses>
      </Screen>
    </Screens>
    </Section>
  </Sections>
</Submission></Submissions> </CanvasResult>

As shown, the data returned will allow us to get the value of anything entered by the user's mobile device.  For any images (including signatures) a URL is provided to be able to either reference or download.

The data is retrieved as XML and parsed using the built in SAX parser.  Once compete, we see the new submission in the list and can view it's details (the last one in the list that is highlighted yellow).

 

 


Last edited 10/02/2014 at 14:11:49


Reply




Copyright 1983-2017 BVSTools
GreenBoard(v3) Powered by the eRPG SDK, MAILTOOL Plus!, GreenTools for Google Apps, jQuery, jQuery UI, BlockUI, CKEditor and running on the IBM i (AKA AS/400, iSeries, System i).