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

Getting the section id of a repeating section which calls a sheet worker

1521050151
David
Sheet Author
Is it possible to get section Id of the repeating section that called a sheet worker.  The only way I have found to do this is to add a hidden attribute inside the fieldset and fill it when the row is created. I hope that makes sense.
1521050623

Edited 1521050659
Jakob
Sheet Author
API Scripter
Walt S said: Is it possible to get section Id of the repeating section that called a sheet worker.  The only way I have found to do this is to add a hidden attribute inside the fieldset and fill it when the row is created. I hope that makes sense. You can use a regular expression to extract the id from the sourceAttribute property of the eventInfo object.
1521051421
David
Sheet Author
Like this on("change:repeating_melee:primWpnSkill", function(eventInfo) { let RID = eventInfo.sourceAttribute.slice(18,38);
1521051821
Jakob
Sheet Author
API Scripter
Walt S said: Like this on("change:repeating_melee:primWpnSkill", function(eventInfo) { let RID = eventInfo.sourceAttribute.slice(18,38); Right, that's even simpler than a regular expression :)
1521052147
Finderski
Pro
Sheet Author
Compendium Curator
Jakob said: Walt S said: Like this on("change:repeating_melee:primWpnSkill", function(eventInfo) { let RID = eventInfo.sourceAttribute.slice(18,38); Right, that's even simpler than a regular expression :) But it would only work for that specific repeating section, so for other repeating sections, the slice would have to change.
1521054272

Edited 1521054377
David
Sheet Author
It will have to work with more than one section so I will have to go delve into regular expressions, thanks Jakob and Finderski for getting me on the right path.
1521056325
Finderski
Pro
Sheet Author
Compendium Curator
Here's a website I found that's been helping me figure out regular expressions (because I'm having to learn them, too): <a href="https://www.regextester.com/?fam=102769" rel="nofollow">https://www.regextester.com/?fam=102769</a> You could paste in several things with row IDs and you'd be able to see if it's finding the correct stuff no matter what the string is.
1521060951
vÍnce
Pro
Sheet Author
&nbsp;I can really mess things up quick, fast and in a hurry with regex.&nbsp; Site bookmarked.&nbsp; Thanks Finderski
1521078505
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I like regexr.com for my regex testing (and you can save patterns you make for use later on)
1521078939

Edited 1521079050
David
Sheet Author
on("change:repeating_melee:primWpnSkill", function(eventInfo) { let sourceA = eventInfo.sourceAttribute let regex = /[^_]*_[^_]*_[^_]*/g; let &nbsp;row = sourceA.match(regex); That was not fun.
Ah, I'm sorry I didn't see this earlier, I actually have a function already to do this in an API script I'm writing. The split() function can also be used to get the rowid and attribute name. var attrinfo = {}; attrinfo.ownerid = obj.get("_characterid"); var name_arr = obj.get("name").split("_"); attrinfo.rowid = name_arr[2]; attrinfo.name = name_arr[3]; attrinfo.current = obj.get("current"); return attrinfo; Of course, in a Sheet Worker you'd use&nbsp;eventInfo.sourceAttribute to get the full name instead of obj.get("name")
1521099095
David
Sheet Author
Thanks Authors, I figured out a split version. &nbsp;I was trying to rise to Jakob's regular expression challenge. &nbsp;