
Hello.
I have a small issue while trying to devise a migration script for a sheet.
The thing is that I have the same repeating section used for different things and I want to split them up.
I found a way to do it, but I think it is awful and I'd be glad if you could give me a hand there.
Here is part of my migration code
getSectionIDs(["repeating_Talents"], function(idarray) {
for(var i=0; i < idarray.length; i++) {
console.log(idarray[i]);
getAttrs(
["repeating_Talents_"+idarray[i]+"_mode-solo",
"repeating_Talents_"+idarray[i]+"_modePage-solo",
"repeating_Talents_"+idarray[i]+"_mode-squad",
"repeating_Talents_"+idarray[i]+"_modePage-squad"], function (values) {
// RETURNS "undefined" :-(
console.log(idarray[i]);
var newSoloRowId = getNewRowId("repeating_SoloModeAbilities_");
var newSquadRowId = getNewRowId("repeating_SquadModeAbilities_");
var newrowattrs = {};
// DOES NOT WORK BECAUSE IDARRAY[I] IS UNDEFINED :-(
newrowattrs[newSoloRowId+"_mode-solo"] = values("repeating_Talents_"+idarray[i]+"_mode-solo");
newrowattrs[newSoloRowId+"_modePage-solo"] = values("repeating_Talents_"+idarray[i]+"_modePage-solo");
newrowattrs[newSquadRowId+"_mode-squad"] = values("repeating_Talents_"+idarray[i]+"_mode-squad");
newrowattrs[newSquadRowId+"_modePage-squad"] = values("repeating_Talents_"+idarray[i]+"_modePage-solo");
setAttrs(newrowattrs);
});
}
});
As you may see in the comments, I cannot get the value names because when I'm in the callback method of getAttrs, I cannot get the value of the id.
I was able to circumvent the problem by doing this, but I really don't like it.
let modeSolo;
let modePageSolo;
let modeSquad;
let modePageSquad;
for (const property in values) {
if(property.endsWith("mode-solo")) { modeSolo = values[property]; }
if(property.endsWith("modePage-solo")) { modePageSolo = values[property]; }
if(property.endsWith("mode-squad")) { modeSquad = values[property]; }
if(property.endsWith("modePage-squad")) { modePageSquad = values[property]; }
}
Do you have an idea to do that better?
Any other hint is nice to have to. I'm far from being a professional JS dev. (but I guess you could gather it from what I wrote :-D)