2

I am running into trouble to trigger a function on edit when REST API software called Workato receives data from Quick Base and inputting in Google Spreadsheet.

Following codes auto sort stated tabs in Google Spreadsheet.

function onPost(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  
   var ApprovedTab = ss.getSheetByName("APPROVED");
     var CollateralPending = ss.getSheetByName("COLLATERAL PENDING");
       var InProcessing = ss.getSheetByName("IN PROCESSING");
            var InClosing = ss.getSheetByName("IN CLOSING");
                  var funded = ss.getSheetByName("FUNDED");
  
  
 var ApprovedTabRange = ApprovedTab.getRange("A2:T99");
   var CollateralPendingRange = CollateralPending.getRange("A2:T99");
      var InProcessingRange = InProcessing.getRange("A2:T99");
         var InClosingRange = InClosing.getRange("A2:T99");
             var fundedRange = funded.getRange("A2:T99");
  
 ApprovedTabRange.sort( { column : 1, ascending: true } );
   CollateralPendingRange.sort( { column : 1, ascending: true } ); 
   InProcessingRange.sort( { column : 1, ascending: true } ); 
   InClosingRange.sort( { column : 1, ascending: true } ); 
   fundedRange.sort( { column : 1, ascending: true } ); 
  
}

When i try using onEdit instead of onPost and manually update a row in spreadsheet, it sorts rows by ID column.

When i try onPost and send a update request from Workato, Google Script function does not run and as result it is not sorting rows.

Any help would be appreciated.

Thank You

2
  • You say you are trying to call onPost with a REST call. Does this mean your script is published as a webapp? Commented Feb 10, 2017 at 18:32
  • No it is not. I am actually super new to Google Scripting. Should i publish it? or Is there any solutions? Thanks Commented Feb 10, 2017 at 18:41

1 Answer 1

3

If I understand correctly, you want to have the spreadsheet automatically call the sorting function after Workato edits data in the sheet.

Since edits via scripts or add-ons don't generate an OnEdit trigger, you'll need to send a separate POST request to trigger a Google Apps Script function in your spreadsheet after Workato updates the data.

In order to call a function via a POST request, you must name the function "doPost()" rather than "onPost()", and you then must Publish the script as a web-app, from the Publish menu.

When publishing the script you will want to "execute as" you, and be accessible to "anyone, even anonymous".

Publishing the script as a web app allows it to receive an incoming GET or POST request, via functions named doGet() or doPost().

See the documentation here: https://developers.google.com/apps-script/guides/web

Sign up to request clarification or add additional context in comments.

8 Comments

Thank you for the respond but it still not triggering the function. I am not sure, if i am missing a step here.
I have updated my function as following doPost, published it as webapp and send a POST request and still function did not trigger and sort. Provided url for the script returns an error saying, "Script function not found: doGet". Altohugh i used doPost, URL says that it is a get method.
The URL will always accept both get and post requests, it runs either doPost or doGet depending on the request type.
Perhaps I am misunderstanding what workato is doing, is it updating the contents of the sheet, and you are then hoping to have it sort after each update? If that is the case you'll need to make a separate post or get request to the web app URL to trigger the sorting.
I have updated my function in Google Script. I now receive this message: The script completed but did not return anything.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.