Export to Google Docs from AppSheet

Also, there is a issue that if you receive a content that is blank you will can end having this error:

Exception: Invalid regular expression pattern {1}
    at exportDocsWithTable(Code:130:14)

This happens because the array will break the sequence of key/value.
To fix this you need to send a value special value if it’s blank and then convert the special value to “”. In other words, you trick the code to believe there is something and then erase the text.

You need to do this treatment ONLY if the field can end being null (a non required field).

First, in the appsheet side, you need to change the field that can be null in the content field of the bot.

instead of:

TEXT("LABEL") ,
TEXT("VALUE")

you have:

TEXT("LABEL")
TEXT(
  IF(
    ISBLANK("VALUE") ,
    "|!@" ,
    "VALUE"
  )
)

you can use anything in the place of “|!@” just make sure it will never be the value of the field.

Next, you need to go to the script and change the following part:

body.replaceText('{' + content[i] + '}', content[i+1]);

to

if(content[i+1] == "|!@") {
 body.replaceText('{' + content[i] + '}', "");
}
else{
 body.replaceText('{' + content[i] + '}', content[i+1]);
}
4 Likes