I’m having a problem with document.newPosition(element,offest). According to the API spec., https://developers.google.com/apps-script/reference/document/document#newPosition(Element,Integer),
the element that will contain the new Position; this must be either a Text element or a container element like Paragraph
I’ve tried both .getText and .editAsText to get a Text element:
var d=DocumentApp.getActiveDocument();
var t1=d.getBody().editAsText();
var t2=d.getBody().getText();
and then
var position = d.newPosition(t1,ix);
var position = d.newPosition(t2,ix);
where ix is an integer that is definitely within the text size.
Using t1 (editAsText), I get :
We're sorry, a server error occurred. Please wait a bit and try again. (line 32, file "testcode”)
where line 32 is the “var position=... line.
Using t2 (getText), I get:
Cannot find method newPosition(string,number). (line 32, file "testcode")
Does anyone know how to get a newPosition with a text element?