'Appending or inserting footnotes programmatically into google doc using google app script

I am using Google App Script to generate a new google doc. The contents of the document come from an array that is looped and paragraph elements are added, or text elements are inserted/appended to pre-existing paragraph elements that were earlier in the loop.

The issue is: some of the items in the array need to be appended or inserted as footnote elements.

The documentation says that footnote elements are contained within listItem or paragraph elements. However there does not seem to be a method to insert footnotes programmatically in the same way that other elements can be inserted into paragraphs - such as appendText() and appendHorizontalRule() etc.

I have not posted any code because I do not know where to begin on this issue. Any guidance is appreciated.



Solution 1:[1]

According to Apps Script documentation,

...there are rules about which types of elements can contain other types. Furthermore, the Document Service in Apps Script can only insert certain types of elements. The tree below shows which elements can be contained by a certain type of element.

More details here https://developers.google.com/apps-script/guides/docs

Footnote and FootnoteSection elements are not highlighted, which means they can't be inserted programmatically.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anton Dementiev