After converting keywords to References, search for keywords is much less useful

This script is working perfectly (no errors, applied to all 200 existing Tasks): thanks for the help!

I’d like to extend it so that in addition to rewriting the rich text with all References replaced by the name of the Referenced entity, it also overwrites a Collection field ([Referenced Tags]) with the list of all Tag References encountered. I can generate the list of Tags easily: at the same point where I replace the Reference with its name in the rich text string I can simply append it to a list: what I don’t know is: how do I pass this list of (Tag) References to the API as a new (set of) values for the [Referenced Tags] Collection field? I think I need to know:

  1. what metadata should I extract from the rich text JSON (and the looked-up Tag JSON) and store for each Referenced Tag? (just the name (string)? the Id? etc.)
  2. what API call I use to replace whatever Tags are currently in [Referenced Tags] with my new list of Referenced Tags?

@ChrisG I think you may given me some of this information already, but I can’t easily find it if so: if you could give me a push in the right direction now I’d appreciate it! Thanks!

PS. Concrete example: let’s say that [Referenced Tags] = (Tag1, Tag2, Tag5) and I apply my script to the Details (rich text) field, which currently contains: "blah blah [T] Tag1 with [T] Tag4 and [T] Tag6" (where the [T]'s represent the embedded Tag References): the result should be that now [Referenced Tags] = (Tag1, Tag4, Tag6).

Update: following example code in Make "creation context" available to scripts - #2 by Chr1sG I tried this:

    const entityWithExtraFields = await fibery.getEntityById(entity.type, entity.id, ['References']);
    const references = entityWithExtraFields['References']
    console.log(references)

but references is empty (didn’t pick up any Tags Referenced in my rich text field). What sort of References should I expect from entityWithExtraFields? (Update 2: I see your comment Make "creation context" available to scripts - #5 by Chr1sG to the effect that References are not available immediately after creation: any idea how long it should take for them to populate? I’m still getting an empty list after about 10 minutes…)