Visual Builder

Get Involved. Join the Conversation.

Topic

    Stephen Bryant
    Posting VBCS Screen (header and lines) to REST...
    Topic posted July 12, 2019 by Stephen BryantBronze Trophy: 5,000+ Points, last edited July 13, 2019, tagged Action Flows, Business Objects, REST, SaaS Integration, UI 
    45 Views, 14 Comments
    Title:
    Posting VBCS Screen (header and lines) to REST Service in ICS (upload to FTP)
    Summary:
    One Header Record, Many Lines
    Content:

    Hello,

    I have a VBCS screen composed of a Header section and a Lines Section.  The header section is tied to a BO while the lines section is based on an ADP.  There will always be one header record to many Lines records.

    I've created an integration in ICS to upload the screen data to two files on an FTP Server where the files will be picked up and processed via FBDI.

    The payload is collected in a vbcs variable based on a variable type tied to the ICS REST endpoint.

    It all works as long as I have one header (no problem) and one line.  It does not work if I have many lines as it simply just adds the first line.  The REST Service does not seem to take the array or recognize that item[i] is an array in the payload.

    I have correctly mapped the Lines Array to the endpoint via the variable created based on the endpoint.

    Headers works fine but I cannot get multiple lines generated.

    Also, I've tested the endpoint in VBCS on the services page with the JSON and that works fine posting multiple lines for each header.  So I am at a loss as to why the array is not recognized.  This is a POST action but to ICS to create the two files.  The service does not error due to content type but works regardless of how many lines I have by creating only one line.  Please advise.

    Am I missing anything?

     

    here is the JSON that works when testing directly from VBCS in the Services Page for the app:

    {  
       "hdrItems":  
          {  
             "docNumber":"123456",
             "fromDocNumber":"123456",
             "budgetLevelId":"1",
             "treasurySymbol":"000-00-0000",
             "fundValue":"0000",
             "publicLawCode":"001-001",
             "transactionDate":"2019-04-24",
             "docTotal":"123456789",
             "fahEvent":"APPROP",
             "hdrDescription":"abcdefg"
          },

       "lineItems":[  
          {  
             "lineDocNum":"123456",
             "glDate":"2019-04-24",
             "glAccountString":"000000000",
             "segment1":"0000",
             "segment2":"000000.00",
             "segment3":"000000",
             "segment4":"0000",
             "segment5":"000000",
             "segment6":"2019",
             "segment7":"000",
             "transactionType":"Appropriation",
             "lineAmount":"123456789",
             "lineDescription":"abcdefg",
             "lineNum":"1",
             "id":"123456",
             "headerId":"123456"
          },

         {  
             "lineDocNum":"123456",
             "glDate":"2019-04-24",
             "glAccountString":"000000000",
             "segment1":"0000",
             "segment2":"000000.00",
             "segment3":"000000",
             "segment4":"0000",
             "segment5":"000000",
             "segment6":"2019",
             "segment7":"000",
             "transactionType":"Appropriation",
             "lineAmount":"123456789",
             "lineDescription":"abcdefg",
             "lineNum":"2",
             "id":"123456",
             "headerId":"123456"
          }
       ]
    }

    Thanks,

    Steve

    Version:
    19.1.3

    Comment

     

    • Shay Shmeltzer

      How are you assigning the lines to the variable that you are passing to the service?

      If you look at the payload sent to the REST endpoint - does it have more than one row in there?

      Is your issue passing the value correctly from VB, or getting it correctly in the integration layer?

       

    • Stephen Bryant

      Shay,

      I need to re-work the lines Payload.  The shape is fine but the fields names do not match so its not picking up anything unless I map the fields directly which will only result in one line.  There are multiple lines but one header.

      Does that make sense?  I think the field names also need to match so I do not have to map them individually to the :Payload variable.  This is all in VBCS.

      Thanks,

      Steve

      • Shay Shmeltzer

        Yes that makes sense.

        If you already have everything defined and you don't want to change that, you can also create an additional array with the right field names, and use a page module JS function to assign the values into that array from your existing SDP/ADP.

         

        • Stephen Bryant

          Shay,

          That is a great idea!  That is what I will do.

          Thanks so much for your help as always,

          Steve

        • Stephen Bryant

          Shay,

          I have the following Array I need to map with the function.

          getAllVBCSLines (source)

          accountSegment

          fundSegment ... and so forth

          I have the following target Array to which the function needs to map

          As you can see, there are two arrays in the Payload (one for headers and one for lines)

          trxLinesArrayPayload (target)

          hdrItems (array)

          docNumber 

          docTotal

          fundValue ... and so forth

          lineItems (array)

           docNumber

          glAccountString

          glDate ... and so forth

          attaching pictures below.

           

          The headers will come from a business object

          The lines are coming from the Array assigned to the ADP

          I am not sure how to  structure the function to refer to only the lineItems.  Here is my code so far:

          PageModule.prototype.mapTrxToPayload = function(trxLinesArray, trxNewLinesArray) {

              trxLinesArray.accountSegment = trxNewLinesArray.segment2;
              trxLinesArray.activitySegment = trxNewLinesArray.segment4;
              trxLinesArray.amount = trxNewLinesArray.lineAmount;
              trxLinesArray.bfySegment = trxNewLinesArray.segment6;
              trxLinesArray.description = trxNewLinesArray.lineDescription;
              trxLinesArray.docNumber = trxNewLinesArray.docNumber;
              trxLinesArray.fundSegment = trxNewLinesArray.segment1;
              trxLinesArray.glAcct = trxNewLinesArray.glAccountString;
              trxLinesArray.glDate = trxNewLinesArray.glDate;
              trxLinesArray.lineNum = trxNewLinesArray.lineNum;
              trxLinesArray.objectSegment = trxNewLinesArray.segment5;
              trxLinesArray.programSegment = trxNewLinesArray.segment3;
              trxLinesArray.orgSegment = trxNewLinesArray.segment7;
              trxLinesArray.transactionType = trxNewLinesArray.transactionType;   

              return trxNewLinesArray;

          Any suggestions on how to map this in the action chain?

          Thanks,

          Steve

           

           

        • Stephen Bryant

          Shay,

          Do I have to actually create another ADP to initialize the new array and then populate it with the values from the old array for the new columns?  I was hoping to populate an array behind the scenes.  I keep getting cannot read property 'segment1'(for example) or undefined).

          Right now, it is not recognizing my variable when I invoke the function for the new array so I am thinking I need to initialize it in the UI?  

          Steve

          • Shay Shmeltzer

            You don't need an ADP - you need an array.

            You send one array into the JS function - loop over the records - assign them to a new array with the right structure and return this new array. You then use an assign variable to assign the new array returned from the JS to the variable you are passing as a body to the POST method.

            Maybe this will help - https://blogs.oracle.com/shay/working-with-arraydataproviders-in-javascript-functions-in-visual-builder

            • Stephen Bryant

              Shay,

              Right now I am trying to loop over the ADP variable that the table is tied to.  Every time I attempt to update the new array, I get a the error.

              How does the function know about the new array if I do not pass it as a parameter?  Do I assign the values in the action chain?

              I am missing something about this.  I will check out the link.

              Steve

               

    • Stephen Bryant

      here is the target payload variable