Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Repeating Sections In Order

1571636133

Edited 1571636182
Is there a mechanism to retrieve attribute values from a repeating section *in the order they exist on the sheet*? $n is returning things in not-the-correct order.
1571643307

Edited 1571643499
GiGs
Pro
Sheet Author
API Scripter
The wiki covers this (in its usual terse manner):&nbsp; <a href="https://wiki.roll20.net/Sheet_Worker_Scripts#getAttrs.28attributeNameArray.2C_callback.29_.5BAsynchronous.5D" rel="nofollow">https://wiki.roll20.net/Sheet_Worker_Scripts#getAttrs.28attributeNameArray.2C_callback.29_.5BAsynchronous.5D</a> You can also request the "_reporder_repeating_&lt;sectionname&gt;" attribute with getAttrs() to get a list of all the IDs in the section that have been ordered. However note that this may not include the full listing of all IDs in a section. Any IDs not in the list that are in the section are assumed to come after the ordered IDs in lexographic order. So using getAttrs, and _reporder you can get the ordered rows, then using getSectionIds you can get the full list of ids. I've never done this, but it sounds like you'd have to subtract out the ordered ones from that second list, and then the ones remaining can be added to the end of the ordered list. I thought I'd seen a worked exampleshowing how to do this on the wiki, but cant find it now. Maybe I'm misremembering. Edit: found it - see the getSectionIDsOrdered function here:&nbsp; <a href="https://wiki.roll20.net/Sheet_Worker_Scripts#getSectionIDs.28section_name.2Ccallback.29_.5BAsynchronous.5D" rel="nofollow">https://wiki.roll20.net/Sheet_Worker_Scripts#getSectionIDs.28section_name.2Ccallback.29_.5BAsynchronous.5D</a> If you experiment with this, let us know how it goes.
1571652779

Edited 1571652826
So the API has access to these functions as well? This is the part that i suppose is confusing me if that's the case. I assumed that the API does not have access to the functions that sheet workers do, because they "don't know" what sheet they're trying to interact with (the script has pulled the character's ID from being handed the character name, but there's no optional parameters to these functions to indicate 'this is the character you're interacting with') This is being sourced from an API script. I suppose I can use a sheet worker to stuff the relevant data into a non-visible attribute and push it along with the API call though. Will investigate this later today.
1571670074
The Aaron
Roll20 Production Team
API Scripter
The API doesn't have access to the same sets of functions as Sheet Workers.&nbsp; And figuring out the order that Attributes are shown in a Repeating Section is a little complicated.&nbsp; &nbsp;Here's a function I wrote that will resolve attributes, including repeating attributes that use the offset index notation: const attrLookup = (character,name,caseSensitive) =&gt; { let match=name.match(/^(repeating_.*)_\$(\d+)_.*$/); if(match){ let index=match[2], attrMatcher=new RegExp(`^${name.replace(/_\$\d+_/,'_([-\\da-zA-Z]+)_')}$`,(caseSensitive?'i':'')), createOrderKeys=[], attrs=_.chain(findObjs({type:'attribute', characterid:character.id})) .map((a)=&gt;{ return {attr:a,match:a.get('name').match(attrMatcher)}; }) .filter((o)=&gt;o.match) .each((o)=&gt;createOrderKeys.push(o.match[1])) .reduce((m,o)=&gt;{ m[o.match[1]]=o.attr; return m;},{}) .value(), sortOrderKeys = _.chain( ((findObjs({ type:'attribute', characterid:character.id, name: `_reporder_${match[1]}` })[0]||{get:_.noop}).get('current') || '' ).split(/\s*,\s*/)) .intersection(createOrderKeys) .union(createOrderKeys) .value(); if(index&lt;sortOrderKeys.length &amp;&amp; _.has(attrs,sortOrderKeys[index])){ return attrs[sortOrderKeys[index]]; } return; } return findObjs({ type:'attribute', characterid:character.id, name: name}, {caseInsensitive: !caseSensitive})[0]; }; The sortOrderKeys in that function ends up being all the attribute's row IDs in sorted order.&nbsp; The way it works is there is a hidden attribute for each repeating section named _reporder_repeating_&lt;SOMETHING&gt; which contains an ordered list of row IDs.&nbsp; The complication is that IDs are only added to that list when they are sorted.&nbsp; If they have not been sorted, they will appear in creation order, which is the order they are returned from a findObjs() call.&nbsp; The above function gets the creation order list, extracts the sorted attributes, and appends the remaining creation order attributes to the end to end up with a sorted list. Hope that helps!