The API doesn't have access to the same sets of functions as Sheet Workers. And figuring out the order that Attributes are shown in a Repeating Section is a little complicated. Here's a function I wrote that will resolve attributes, including repeating attributes that use the offset index notation: const attrLookup = (character,name,caseSensitive) => {
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)=>{
return {attr:a,match:a.get('name').match(attrMatcher)};
})
.filter((o)=>o.match)
.each((o)=>createOrderKeys.push(o.match[1]))
.reduce((m,o)=>{ 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<sortOrderKeys.length && _.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. The way it works is there is a hidden attribute for each repeating section named _reporder_repeating_<SOMETHING> which contains an ordered list of row IDs. The complication is that IDs are only added to that list when they are sorted. If they have not been sorted, they will appear in creation order, which is the order they are returned from a findObjs() call. 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!