Home > Back-end >  How To Put A Number In Front Of Every Suggestion Corretcly?
How To Put A Number In Front Of Every Suggestion Corretcly?

Time:01-27

Detail Of The Problem

As title, I am using Google App Script and Google Docs API's Batchupdate, trying to put number in front of every suggestion. However, I can place it correctly at the very first one, but it starts to deviate after the first one.

Result I Currently Have

Please refer to the image below. Result I Currently Have

What I have Tried

Below is the snippet I currently have

function markNumberInFrontOfMark(fileID) {
  fileID = "MYFILEID";
  let doc = Docs.Documents.get(fileID);
  let requests = doc.body.content.flatMap(content => {
    if (content.paragraph) {
      let elements = content.paragraph.elements;
      return elements.flatMap(element => element.textRun.suggestedDeletionIds ? {
        insertText: {
          text: "(1)",
          location: {
            index: element.startIndex
          }
        }
      } : []);
    }
    return [];
  });
  Docs.Documents.batchUpdate({requests}, fileID);
  return true;
}

Result I Want To Have

Please refer to the image below

Result I Want To Have

Post I Refer to

enter image description here

  • Related