Feels like I’m very close but still no sigar.
To repeat I try to save the tags of a document (the tags are “tag1”, “tag2”, and “tag3”) into the format under to export it to a Notion multi_select property. In this example I manually inserted “tag1”, “tag2”, “tag3”, but the goal is to make the script insert an undefined number of tags into the same format with a loop (or other methods if they exist).
let notetags = [
{ "name": "tag1" },
{ "name": "tag2" },
{ "name": "tag3" },
] ;
Later in the script this is recalled as follows:
"Tags": {
"multi_select":
notetags
} ,
So far so good. Then I tried to use the drafts.tags.map function agiletortoise recommended. I ended up with the following script:
let temptags = draft.tags.map(t => {
return { "name" : t }
})
let notetag = "[ ";
for (let i = 0; i < temptags.length;i++) {
notetag += temptags[i];
}
notetag += " ]"
I first tried to imput this into a “rich_text” property in the Notion database which is more forgiving and might give tips about what is wrong. I was able to create an entry but the the result was
[ [object Object][object Object][object Object] ]
I then tried to convert the object/array to a string with stringify and added a comma between elements:
let temptags = draft.tags.map(t => {
return { "name" : t }
})
let notetag = "[ ";
for (let i = 0; i < temptags.length;i++) {
notetag += JSON.stringify(otags[i]) + ", ";
}
notetag += " ]"
The output is now:
[ {“name”:“tag1”}, {“name”:“tag2”}, {“name”:“tag3”}, ]
Which is exactly what I want, but when I tried to recall this string to the multi_select property no entry in Notion is created (but no error in drafts).
Any idea why it is still not working? I have a feeling it has something to do with properties of objects/arrays vs string but not able to figure it out…