Visual Builder

Get Involved. Join the Conversation.

Topic

    Stephen Bryant
    Business Object Function - return array with multiple...
    Topic posted November 13, 2019 by Stephen BryantBronze Trophy: 5,000+ Points, tagged Action Flows, Business Objects, Custom Code, Groovy, REST, SaaS Integration 
    11 Views, 2 Comments
    Title:
    Business Object Function - return array with multiple records
    Summary:
    Business Object Function - return array with multiple records to pass to web service
    Content:

    Hello,

    I have BO called, TrxHdrs, with multiple records.  I know I can create a BO Object Function to iterate over those records.

    What I would like to do is write records that, for example, have a Status of, "available", to an array.  I want to write the entire record where the criterion is met.  Then I would like to pass the result (with multiple rows) to a web service (integration cloud) that sends it to ERP Cloud.  The only thing I need help with is how to create an array with multiple records in groovy.  The array will be structured to match what is expected by the web service.

    I am thinking each record would be a list with key-value pairs and many records would be contained within a "parent array". That would be the result to pass to the web service.

    In VBCS, I am able to iterate over and ADP and pass a single result to the web service successfully.  I am looking to do the same thing but get the data from the BO. 

    Any help is appreciated.

    Steve    

    Version:
    19.3.1.2

    Comment

     

    • David Konecny

      re "I need help with is how to create an array with multiple records in groovy" - that should be as simple as:

      def myRecords = []
      def newRecord = [:]
      newRecord["id"] = 123
      newRecord["name"] = "A name"
      myRecords.add(newRecord);

      is that what you are asking for (individual records are Groovy Map objects)? The tricky part will be how to encode that Groovy array into payload for your REST call. I have not done this so I cant say for sure that passing such array as payload in your REST call will automatically convert it into JSON. I know that it is NOT possible to convert Groovy objects into JSON using eg JsonOutput.toJson(groovyArray). And manually encoding array into textual JSON format will be bit of an effort.

      -David