You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

If you have already learned how to add a property or a sub-property to a resource object, you already know the basics of how these GetObject companion services work. As one might expect, there is an AddSubResource service available for this task. However, there is another service named AddSubResourceObject, which can also be used. Both will be explained below.

AddSubResource Service

The calling signature for the AddSubResource service is virtually identical to the AddSubProperties service (i.e., the plural version of the AddSubProperty service). The key difference is that when the AddSubProperties service is called more than once for the same parent property name and the same sub-property names, the new sub-property values replaces the old ones. Whereas with the AddSubResource service, each time it is called a new sub-resource object is added (or appended) to the existing array of sub-resources associated with the parent property. Here is an example of what the code might look like:

objResource     = HTTP_Resource_Services('GetObject')
If Error_Services('NoError') then
    SubResourcePropertyNames    = 'type'     : @FM : 'address'            : @FM : 'city'        : @FM : 'county'  : @FM : 'state' : @FM : 'zip'
    SubResourcePropertyValues   = 'Mailing'  : @FM : 'PO Box 1234'        : @FM : 'New Orleans' : @FM : 'Orleans' : @FM : 'LA'    : @FM : '70116'
    HTTP_Resource_Services('AddSubResource', objResource, 'address', SubResourcePropertyNames, SubResourcePropertyValues)
    SubResourcePropertyValues   = 'Shipping' : @FM : '6649 N Blue Gum St' : @FM : 'New Orleans' : @FM : 'Orleans' : @FM : 'LA'    : @FM : '70116'
    HTTP_Resource_Services('AddSubResource', objResource, 'address', SubResourcePropertyNames, SubResourcePropertyValues)
    // Serialize the JSON object.
    jsonResource    = HTTP_Resource_Services('GetSerializedResource', objResource)
end

Because we are adding entire resources with each call to the AddSubResource service, the entire sub-resource must be passed in at once. Our resulting resource object will look like this:

{
   "address":[
      {
         "type":"Mailing",
         "address":"PO Box 1234",
         "city":"New Orleans",
         "county":"Orleans",
         "state":"LA",
         "zip":"70116"
      },
      {
         "type":"Shipping",
         "address":"6649 N Blue Gum St",
         "city":"New Orleans",
         "county":"Orleans",
         "state":"LA",
         "zip":"70116"
      }
   ]
}

Actual code will likely loop through each value of a master AMV field or each row as it is read from a database cursor and call the AddSubResource service in the same loop.

AddSubResourceObject Service

  • No labels