Search code examples
google-apps-scriptgoogle-docs

Use Google App Script to write a phone number to a doc that allows user to select the whole number with single press


I'm using App Script to create a residents directory (a Google Doc) for our neighborhood. Phone numbers look good but when the user presses on the phone number to select it, only a portion delimited by "-" selects (then the user must drag to select the whole number). We would like the entire phone number to be selectable as a single unit so it is easy for our resident to select, then call.

var thePhoneNumber = "111-222-3333";
theTableCell.appendParagraph(thePhoneNumber);

In the example above, a user presses on "222" and only gets "222", not "111-222-3333". Is there a way to do this?


Solution

  • You could try setting a tel link:

    const thePhoneNumber = "111-222-3333";
    theTableCell
        .setText(thePhoneNumber)
        .setLinkUrl(`tel:${thePhoneNumber.replace(/-/g,"")}`);