Page History
...
The AddSubResource service works like the AddProperty and AddSubProperty service in that serialized data is expected to be passed in through the arguments. The AddSubResourceObject service allows the developer to pass in an @FM delimited list of object handles.an object handle. This is particularly useful when the sub-resource object itself is too complex to be created using the AddSubResource service alone (which only knows how to create a flat sub-resource of property names and values). In the What is a sub-resource? article we note that sub-resources can be as complex as any resource. In fact, it is possible for sub-resources to contain sub-resources and so on.
Therefore, in order to add a complex sub-resource to a resource object, it is necessary to build the sub-resource object using other services (e.g., GetObject, AddProperty, AddSubProperty, etc.) and then use the object handle in the AddSubResourceObject service. Here is how the above code would be re-written using the AddSubResourceObject service:
Code Block | ||
---|---|---|
| ||
objResource = HTTP_Resource_Services('GetObject')
If Error_Services('NoError') then
PropertyNames = 'type' : @FM : 'address' : @FM : 'city' : @FM : 'county' : @FM : 'state' : @FM : 'zip'
PropertyValues = 'Mailing' : @FM : 'PO Box 1234' : @FM : 'New Orleans' : @FM : 'Orleans' : @FM : 'LA' : @FM : '70116'
objSubResource = HTTP_Resource_Services('GetObject')
HTTP_Resource_Services('AddProperties', objSubResource, PropertyNames, PropertyValues)
HTTP_Resource_Services('AddSubResourceObject', objResource, 'address', objSubResource)
PropertyValues = 'Shipping' : @FM : '6649 N Blue Gum St' : @FM : 'New Orleans' : @FM : 'Orleans' : @FM : 'LA' : @FM : '70116'
objSubResource = HTTP_Resource_Services('GetObject')
HTTP_Resource_Services('AddProperties', objSubResource, PropertyNames, PropertyValues)
HTTP_Resource_Services('AddSubResourceObject', objResource, 'address', objSubResource)
// Serialize the JSON object.
jsonResource = HTTP_Resource_Services('GetSerializedResource', objResource)
end |