Normally, when building REST Services for smartUI, you’ll have to read complex attributes from categories to send them for display to a widget.
Lets use this example
In your REST handler, you r task would be to get the values of the category attached to a node, read them and send them to the client using REST.
In this writing, we’ll focus on the “Read them” part. Our trick is
object LLNODE = $LLIAPI.LLNodeSubsystem.GetItem(node.pSubtype) result = LLNODE.NodeCategoriesGet(node)
Thos gives us all Categories connected to a node.
When we receive the REST call in ther server handler, we should do
- find the node id of the the object to examine.
- find the categories attached to this node (Red Arrow in the Screenshot)
- iterate over all categories and get the attributes we want. This is based on
- the attribute definitions (Green Arrow on the Screenshot)
- the attribute values (Yellow Arrow on the Screenshot)
- if you encounter a set (-18 as attribute type), you also will have to iterate over the set (Red Rectangle)
Lets take a look on the Values of a single Category. They are inside an assoc with one entry per attribute id.
Now you are almost done. Put a switch construct to get all values of the attributes on which you are intersted and get them out of the fdata assoc. The Value is found in the fdata assoc of the n-th Category unter the content of the first Value entry. Then we have to pick the attribute id where we find the content of the attribute in the first Value entry.
The Str,ValueTostring typecasts the output to be a string. So when we finished the job, we’ll see in the entry event.eventcycle the value of the attribute with the name “EventCycle”.
The only thing to do is put the values in assocs and send them to the smartUI widget under the main clause “events” in the JSON array
So you see, Categories are no Monsters. They are quite user friendly. Using the same mechanism, you can even update complex Categories with one REST call.
Happy smartUI programming.
New: We are offering custom widget development. Interested? Send an e-mail at merz at ebit-company.de stating the purpose of the widget and requesting an offering