There appears to be a bug in cs.get_component(“XXXXX”).get_properties() function
According to the provided instructions (documentation), we need to iterate through the list provided by the above call to get the individual properties data (schema).
while (props.next_row()) {
properties.push(props.current());
}
is provided as the example
The problem is that the very first call of next_row() actually provides the second element from the list (item (1)) and will run and include a blank element at the end.
This means we have to do a props.current() before looping the list (to get item (0)) and then manually expunge an additional element created at the end when it overflows by an element (actually returns an empty array).
Seems like a bug to me ?
Anyone else noticed this - will likely raise to Netcall for investigation but maybe I’ve missed the point somewhere ?
Hi, looks like it is working correctly but the example is wrong.
props.current()
will already point to the first (0) item, so should be output first, before then calling props.next_row() to move to the next one. So the example here should instead be:
do {
properties.push(props.current());
} while (props.next_row());
We’ll get the documentation updated.
next_row() does overflow the end of the list though leading to an empty element in the last position.
I mean its not a problem per say but does require an extra step to then splice(-1) the final element out.
Oh yeah, that is not ideal. I’ll raise a bug. I imagine next_row should return false when it reaches the end maybe.
I’m not sure why we have to use these special iterator methods at all, and why it doesn’t just return standard objects.
Yes particularly as in this case you can actually still use
cs.record(-1).schema(“XXXXX”)
or variants thereof to achieve the same thing
without all the additional processing that would likely be required for the newer options.
and yes im aware that could also be deprecated in time ….
Its hard to see at the moment how you use the alternative to get things like subsets etc too
I’ve had a look at the code and it turns out you don’t need to use both next_row and current, the following will work as you want:
while (prop = properties.next_row()) {
// Use prop here
cs.log(prop);
}
This is because next_row() also returns the current item before moving the pointer on. I’ll update the examples in the Docs.
By the way, getting subsets would be as follows for example:
let subsets = cs.get_components('subset', { 'object_id' : cs.ref('my_object') });
The filter on object ID is optional, but you probably want it in most cases.
This is always the challenge I face Bob. Finding where this stuff is actually documented 
As far as I can tell neither the online or the CS documentation give that level of detail and although it might be possible to infer this kind of approach with enough experience of the platform - beginners have no chance !!!
just noticed the subtle difference - get_components()
ill retract my small moan 
1 Like