Issue in retrieving newly created paragraph element

Do you want to: Report a bug
Document Server version:
Additional information:
I have been trying to insert some text at current cursor position, i am using insertContent method to add text to paragraph and i need to be able to get the range or select the text. i am not able to get the element range or not able to select. I am in requirement of creating a bookmark programatically i.e adding text in document and then apply bookmark. I am using the code in plugin & macros.

(function()
{
    const oDocument = Api.GetDocument();
    const oParagraph = Api.CreateParagraph();
    const oRun = Api.CreateRun();
    debugger;
    let oVariableName = `{{aaaa}}`;
    oRun.AddText(oVariableName);
    oParagraph.AddElement(oRun);
    oDocument.InsertContent([oParagraph], true);
    const paraSelected = oParagraph.Select();
    console.log(paraSelected);
    if (!paraSelected) {
        const runSelected = oRun.Select();
        console.log('RUN selected', runSelected);
    }
})();

on fetching paragraph methods such as GetRange, it throws error and returns null for GetPosInParent and Select doesn’t work either. How do we get the element position for newly created elementsin plugins or macros

Error for GetRange method

Hello @agamdev

I’m not sure if this behavior is a bug. Considering that InsertContent() is used with isInline:true, it does not actually create a paragraph, hence you cannot get it after insertion. On the other hand, you cannot select paragraph before using InsertContent() since it is not in the document yet.

Can you share what kind of variable content is usually used? It is static or dynamic? If dynamic, then I believe you can use a workaround with Search method by using the same variable to perform search, then select that search and use GetRangeBySelect to further execute AddBookmark for returned range.