Replace bookmark by combobox


I want to replace bookmarks with “combo” in their name with a combobox.

Children of paragraghs such as combobox or paragraph cannot be inserted from a range.

How should I do it ?

thanks in advance

from OnlyOffice

Hello @David33
We’re checking the situation, I will update this thread as soon as possible.
By the way, your Document server (v.7.1) is outdated. We recommend to update installation timely.

in fact i am using


After a lot of reading and trying I found this way :

oRange.Delete(); // this seem to put the current cursor (the current position in the doc) at the deleted range.
oDocument.InsertContent([oComboBoxForm]); // this insert new content at the current cursor

All the best,

We’re glad that you managed the situation. Please feel free to contact us if you face any issues.

Sorry, in fact some times it does not work and return " Uncaught TypeError: Cannot read property ‘ea’ of undefined " ?

It works if i put the contentControl in an InlineLvlSdt and in a created paragraph :

var oInlineLvlSdt1 = Api.CreateInlineLvlSdt();
oInlineLvlSdt1.AddText(“InlineLvlStd Label”);
var oParagraph = Api.CreateParagraph();

BUT, the insertion of a paragraph add also a space and a carriage return after the paragraph.

Is it possible to delete those spaces and the carriages returns and how ?

Or is it possible to replace the paragragh container by an appropriate inline container that can be inserted at the current range selection ?


Could you please share your test file and script itself (with detailed description of the issue) with us? We will check it out.

  1. source doc is test.docx - Google Docs

  2. php execute a docbuilder script to retrieve the textual content of the doc and parses all the variables, defined by a sequence of alphanum characters with at least one underscore.

$vars is :
[ADR1_FIXE_CONSO] => adr1_fixe_conso
[ADR2_FIXE_CONSO] => adr2_fixe_conso
[ADR3_FIXE_CONSO] => adr3_fixe_conso
[ADR4_FIXE_CONSO] => adr4_fixe_conso
[ADRES1_EXPEDITION] => Adres1_expedition
[ADRES2_EXPEDITION] => Adres2_expedition
[ADRES3_EXPEDITION] => Adres3_expedition
[ADRES4_EXPEDITION] => Adres4_expedition
[CODE_CIV_EXPEDITION] => Code_Civ_expedition
[COMPL_EXPEDITION] => Compl_expedition
[DATE_IMPRESSION] => Date_impression
[NOM_EXPEDITION] => Nom_expedition
[NUM_DERNIER_PRODUIT_ACTIF] => Num_dernier_produit_actif
[NUM_ID] => Num_id
[V_A] => V_A
[V_B] => V_B

  1. Then i would like a docbuilder script (run by PHP which knows the vars) to replace all vars by an appropriate content control (simple inline text or simple inline combobox) :
$out['docBuilder_script'] ='
builder.OpenFile("' . $docx . '");
var oDocument = Api.GetDocument() , aBookmarks = oDocument.GetAllBookmarksNames() ;

// remove all bookmarks
aBookmarks.forEach(function(element, index, Array) {
           var oRange = oDocument.GetBookmarkRange(element);



if( is_array($vars)){
       foreach ($vars as $k => $v) {
           $v = trim($v);  
           $out['docBuilder_script'] .='

           var aSearch = oDocument.Search("' . $v . '"),  aSearchNb = aSearch.length;
           for (var i = 0; i < aSearchNb  ; i++ ){

               // Bookmark name must be unique. So trying to suffix the item with its occurence number.
               // BUT it displays 5 items of "V_A" and "V_B" instead of the 3 from the source.
               // It seems like the initial search is refreshed after each replacement ???

               var suffix = ""; if(aSearch.length>1) suffix = "__" + (i+ 1);              

               aSearch[i].AddBookmark("'.$v.'" + suffix );

               var oI = Api.CreateInlineLvlSdt();
                   oI.AddText("' .$v . '"+suffix);
                   oI.SetAlias("' . $v . '"+suffix);
                   oI.SetPlaceholderText("' . $v . '"+suffix);
                   oI.SetTag("' .$v . '" );

               var oP = Api.CreateParagraph();

               // This insert oP at the current selection, the search item current selection via aSearch[i].Select();
               // oDocument.InsertContent([oI]); throws error "Uncaught TypeError: Cannot read property ea of undefined"
               // oDocument.InsertContent([oP]); works BUT a carriage return and a space is added after the block insertion.



   $out['docBuilder_script'] .='
   builder.SaveFile("docx", "' . $docx . '");
  1. result is

  2. Questions are :

  1. With the docbuilder script, how to replace the content of a range - via search() or GetAllBookmarksNames() results - with an inline content control or inline combobox, keeping the range’s original display styles ?

    In fact I just wish I could do the same as what is done in the GUI :

    • text selection in the doc + menu insert / content control / plain text
    • insert / content control / highlight settings + color choice
  2. How to avoid having additional variable generations? I mean I should only have V_A_1, V_A_2 and V_A_3. What is wrong ?

  3. Ranges are highligtable. Thus, I can highlight in yellow all the variables of my document. But how do you remove all highlights from these vars? I tried to use bookmark containers but they need a unique id and when I try to name them with their occurrence number it becomes a mess?