Copy & replace text of a block used inside structured text field


We have a block - id, title, body. → body field is HTML
Now we changed the block to have fields - id, title, body, new_body. → new_body is structured text field.

we have written a script to convert HTML text to ST which is working fine.

This block is used inside a structured text field.

We want to migrate all the data from body field to new_body field. What’s a good way to do this?

Hello @rislam1

We have a tool specifically designed to convert HTML fields into Structured Text fields, you can get it and see its documentation here: structured-text/packages/html-to-structured-text at main · datocms/structured-text · GitHub

As I mentioned, this part is done following that doc. The problem is body, new_body fields are fields of a block. this block was added to a structured text field. Have u got my point?

The process should be the same for fields inside blocks. When inputing the HTML you should get the field from the block, the same way you would get any value from a block, and when setting the Structured text output from the provided function into the block, you should use the buildModularBlock function, as same as setting a plain value to a block.
Are you encountering any specific problems when reading/writing to a block?

how can i read that block’s field value? Do I need to parse ST field.


  • Article (model)
    ---- description (ST field of model)
    ------ Fact (Block)
    -------- body
    -------- new_body

You can request the record using the parameter
nested: true
To return all nested block values inside the structured text when requesting the records

This will return a response with the block values inside the structured text, allowing you to read that blocks field value.

so as I guessed I have to loop through.