I am trying to add rows to a repeating section on first
opening the character sheet. I have a field named ‘attr_opened’ which is set to 0 on
creation, and then set to 1 ofter the rows are added so that they are no added
again. Having read through the various forums on sheet creation and
sheetworks, I have been led to believe that it is possible. I created a listener to check for first opening and then create the entry in the repeating section. on('sheet:opened', function() { getAttrs(['opened'],function(v) { var op = parseInt(v.opened); if(op !==0) return; constrid1 = generateRowID(); varnewTalentid = "repeating_talents_" + rid1 + "_talentname" setAttrs({opened:1, newTalentid:'speak(common)' }); }); }); It correctly identifies if the sheet has been opened before
and if not changes the value of opened to 1.
The repeating section I am trying to add to is called
repeating_talents and the primary field within it is attr_talentname. There are
other fields in the repeat section I will wish to add to, but for now I will be
happy if I can get it to add just the name of the talent.
I have output the variable newTalentid to a text field to
check it is being generated correctly – it is. For example: repeating_talents_-NdyY-9tYB3o0VLarmnU_talentname
I have also tried the following code (taken from a forum
post <a href="https://wiki.roll20.net/Sheet_Worker_Scripts" rel="nofollow">https://wiki.roll20.net/Sheet_Worker_Scripts</a>
and <a href="https://help.roll20.net/hc/en-us/articles/360037773513#getsectionids-section-name-callback-asynchronous-0-18" rel="nofollow">https://help.roll20.net/hc/en-us/articles/360037773513#getsectionids-section-name-callback-asynchronous-0-18</a>
) on('sheet:opened', function() { getAttrs(['opened'], function(v) { varop = parseInt(v.opened); if (op !==0) return; const rid1 = generateRowID(); const newTalent ={}; newTalent["repeating_talents_" + rid1 + "_talentname"] = "speak(common)"; setAttrs({ opened: 1 }); setAttrs(newTalent); }); });
But this just broke the shhet altogether. Can anyone point out where I am going awry?