Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Admittedly, the AddSubResourceObject service appears to require more code to implement than the AddSubResource service. For simple sub-resource objects this is true but . But as already noted, the AddSubResourceObject service is intended for more complex sub-resource objects. It is also quite useful when another service routine is responsible for creating the object handles handle and these are this is returned conveniently to be used in the AddSubResourceObject service.a calling routine and used in the AddSubResourceObject service.

At this time we will introduce the AddSubResourceObjects service. This is a wrapper around the AddSubResourceObject service and it accepts an @FM delimited list of object handles. This is quite useful when a separate routine returns multiple objects handles at once. The below code demonstrates this in action using the GetObjects service and the AddSubResourcesObjects service:

Code Block
languagebp
objResource     = HTTP_Resource_Services('GetObject')
If Error_Services('NoError') then
    objSubResources = HTTP_Resource_Services('GetObjects', 'CONTACTS', 'SELECT CONTACTS WITH FIRST_NAME STARTING "H"', 'FIRST_NAME' : @FM : 'LAST_NAME', 'firstName' : @FM : 'lastName')
    HTTP_Resource_Services('AddSubResourceObjects', objResource, 'contacts', objSubResources)
    // Serialize the JSON object.
    jsonResource    = HTTP_Resource_Services('GetSerializedResource', objResource)
end

When this code is tested against the default CONTACTS table that ships with the SRP HTTP Framework, the following resource object is produced:

Code Block
languagejs
{
   "contacts":[
      {
         "firstName":"Harrison",
         "lastName":"Haufler"
      },
      {
         "firstName":"Haydee",
         "lastName":"Denooyer"
      },
      {
         "firstName":"Heike",
         "lastName":"Berganza"
      },
      {
         "firstName":"Helga",
         "lastName":"Fredicks"
      },
      {
         "firstName":"Herman",
         "lastName":"Demesa"
      },
      {
         "firstName":"Herminia",
         "lastName":"Nicolozakes"
      },
      {
         "firstName":"Hillary",
         "lastName":"Skulski"
      },
      {
         "firstName":"Howard",
         "lastName":"Paulas"
      }
   ]
}


{
"contacts":[
{
"firstName":"Harrison",
"lastName":"Haufler"
},
{
"firstName":"Haydee",
"lastName":"Denooyer"
},
{
"firstName":"Heike",
"lastName":"Berganza"
},
{
"firstName":"Helga",
"lastName":"Fredicks"
},
{
"firstName":"Herman",
"lastName":"Demesa"
},
{
"firstName":"Herminia",
"lastName":"Nicolozakes"
},
{
"firstName":"Hillary",
"lastName":"Skulski"
},
{
"firstName":"Howard",
"lastName":"Paulas"
}
]
}