Docs Inserted Image always before all text

Viewed 61

Making a simple app script that puts images and Text into a Google Doc separated by 2 Columns, for whatever reason, no matter the way I try it the images are always above the text (Inline) in the Doc, even though they should be layered (Inline),

 //Replace QR Code
  
  let qrText = editLocalBody.findText("{{qrCode}}");
  let setImagePlace = qrText.getElement().asText().replaceText("{{qrCode}}", "");
  let qrCodeImage = setImagePlace.getParent().asParagraph().insertInlineImage(0, qrCodeBlob); 

From what I've seen this should insert an image wherever the text was previously located, but when it runs this it's always in the wrong spot, somehow above the text it was suppost to be in!

//Edit - To Show The Progression Of What Is Suppose To Happen And What Actually Happens:

I'm making QR Code badges for a propriety system that runs integrated tightly with Google, so I'm using appscript to get an entry from a google form containing an amount of badges (With relevent data) and autofill a Google Doc Accordingly.

// Loop Start

I fill my template with a text line that has key words in it I can select and replace later, with a keyword it can use to insert another this (This Part Works)

I first edit (findText("{{qrCode}}");) the QR Code, replacing (.replaceText) the keyword for it to nothing ("")

I then get the parent of the piece of code I ran above, which is a block of text (I think all the text in the Doc, I think this is where the issue lies, it puts it above the text because it's just one 'paragraph' or not multiple 'bodies' of text, if I could separate this I think it would work!) As a paragraph, and insert An Inline Image at Child Index (0, of the image ,qrCodeBlob)

I've debugged this script quite a bit, so I know It's that final line that inserting images fails, it sees all the text as 'one'.

// I want this (In Descending Order, each it's own full line): Image Text Image Text

//What It Gives Me (In Descending Order, each it's own full line): Image Image Text Text

 let qrCodeImage = setImagePlace.getParent().asParagraph().insertInlineImage(0, qrCodeBlob); 
0 Answers
Related