0

I have a spreadsheet linked to a standalone script that imports task from my tasklist. It works fine when I am the user but does not work in share user account.

The codes in the standalone script is

function getTasks() {

  var tasklistID="mytasklistid";  
  var tasks=Tasks.Tasks.list(tasklistID);
  return tasks

}

Code in Bound script is


function getTask(){

var tasks = TaskManagerScript.getTasks()
Browser.msgBox(tasks)

}

When I run the code in my account I get the tasks from tasklist with the specified id as expected. But when I run it from a different user account I get the the tasklist of the other user.

How do I make the code return the tasks from the list with the specified id when other users run it.

Rubén
  • 34,714
  • 9
  • 70
  • 166
Sheils
  • 323
  • 2
  • 22
  • I have 2 questions. 1. Can I ask you about ``a spreadsheet linked to a standalone script that imports task from my tasklist.``? 2. How do users run the script? – Tanaike Apr 24 '19 at 07:04
  • @Tanaike The spreadsheet use the standalone script as library. To get the result in my question I run the script directly from the sheet's bounded script. I real life the user will enter the name of the person completing the task and click completed. This triggers code to update that task id. Then a code to import todays umcompeted task and update the spreadsheet is run. The code shown in my question is the first step in this process. – Sheils Apr 24 '19 at 15:19
  • Thank you for replying. About ``user will enter the name of the person completing the task and click completed``, an user put a value to a cell and click a button put in the sheet. The script is run by clicking the button. Is my understanding correct? – Tanaike Apr 24 '19 at 23:49
  • @Tanaike The script run on the onEdit (Installed trigger) if there is a name of the completed by cell and the checkbox in the completed column of the row being edited is ticked. – Sheils Apr 25 '19 at 05:20
  • Thank you for replying. From your reply comments and question, I proposed a confirmation point as an answer. Could you please confirm it? If I misunderstood your situation and this didn't work, I apologize. – Tanaike Apr 25 '19 at 06:24
  • Thank you for replying. I apologize for the inconvenience. In my environment, I could confirm that the flow of my answer worked. So I think that there might be other issues. So I would like to confirm about it. If I found the clear reason, I would like to report it. So in the current stage, I would like to remove my answer once, because I don't want to make other users confuse.I apologize I couldn't find your issue soon. – Tanaike Apr 25 '19 at 12:09
  • Hi Tanaike, I actually found your answer very helpful. It was a good tool for testing that the task importing works.Now that this is confirmed I can go look for the source of other errors in my code. Noting the title of my question "_How to refer to my tasklist in a standalone script that will be used by other user?_", I would say that your answer was very relevant and you be happy to accept it as the correct answer. – Sheils Apr 25 '19 at 16:55
  • At [my comment](https://stackoverflow.com/questions/55822975/how-to-refer-to-my-tasklist-in-a-standalone-script-that-will-be-used-by-other-us?noredirect=1#comment98343541_55822975), I have asked ``an user put a value to a cell and click a button put in the sheet. The script is run by clicking the button. Is my understanding correct?``. For my question, you answered ``The script run on the onEdit (Installed trigger) if there is a name of the completed by cell and the checkbox in the completed column of the row being edited is ticked.``. By this, I proposed a flow for using OnEdit event trigger. – Tanaike Apr 25 '19 at 22:16
  • I think that my answer can be used for this situation. But from [your this reply](https://stackoverflow.com/questions/55822975/how-to-refer-to-my-tasklist-in-a-standalone-script-that-will-be-used-by-other-us#comment98374098_55838084), you said ``I am still having is to get the code to fetch a list of task when a button is clicked on the spreadsheet.``. In this case, the script is run as users. By this, users cannot use your task list ID. I think that the reason of your issue is this. I apologize I couldn't image this situation. For this situation, other workaround is required to be proposed. – Tanaike Apr 25 '19 at 22:17
  • @Tanaike I agree the button sounds like a separate issue requiring a different work around and should be a a new post. I like your answer as it provides a clear step by step guide on how to import task into shared spreadsheet to that the task can be manipulate by "different" users. I have not seen anything as good as that elsewhere. So please post your answer again as many will find it useful. I will close this question once I hear back from you. – Sheils Apr 26 '19 at 04:00
  • Thank you for replying. I could understand your reply. So I undeleted my answer and added the information. Could you please confirm it? – Tanaike Apr 26 '19 at 04:49
  • Thanks, your answer has reloaded and I can marked it as accepted answer. – Sheils Apr 26 '19 at 05:18
  • Thank you for replying. I think that in order to completely achieve your goal, there is one more situation. So if you posted another question related to the situation using a button, also I would like to think of about your solution. – Tanaike Apr 26 '19 at 23:31

2 Answers2

1
  • You are using a container-bound script of Spreadsheet, and the bound script installs a library.
  • The Spreadsheet is shared by users. You are an owner of Spreadsheet.
  • You want to make users use your task ID.
  • You want to run the script by the OnEdit event trigger.

If my understanding is correct, how about this answer?

OnEdit event trigger is run as owner of Spreadsheet. So when users edit the Spreadsheet, the script is run with your task list ID. But from your question, it's when I run it from a different user account I get the the tasklist of the other user.. I could confirm that in my environment, when users edit to the shared Spreadsheet, the script is run as owner (me), and my task list ID could be used. Unfortunately, I couldn't replicate your situation. So, in order to confirm this situation, can you test the following flow?

Sample flow for testing:

  1. Create new Spreadsheet.
  2. Open the script editor and install the library of TaskManagerScript.
  3. Enable Tasks API at Advanced Google Services.
  4. Put the script to the script editor. The script is as follows.

    function getTask(e) {
      var tasks = TaskManagerScript.getTasks();
      e.source.appendRow([JSON.stringify(tasks)]);
    }
    
  5. Install OnEdit trigger to getTasks().

  6. In order to authorize, please run getTasks() by the script editor and authorize the scopes.
    • In this case, an error occurs. But don't worry. This action is used only for authorizing.
    • This authorization might not be required. But this is just in case.
  7. Share the Spreadsheet to user who is not your account.
  8. The user edits the sheet.

By above flow, when the user edits the sheet, the result retrieved with your task list ID is returned.

Note:

  • When OnEdit event trigger runs the script by editing the cells by users, the script is run as owner of Spreadsheet. But when the script is run by clicking a button on the sheet and the custom menu, the script is run as each user. Please be careful this.

Reference:

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • Hi Tanaike, Thanks for helping. I followed your steps and it shows my task when I run it in the other user's account. So error must be somewhere else. When I try to run my original code I get this error:-API call to tasks.tasks.list failed with error: Not Found. The full code that I am trying to run is `var TaskDate=new Date() //Some code to get TaskDate var listoftasks = Tasks.Tasks.list(tasklistID) var filteredtask=listoftasks["items"].filter(function(item){return item["due"]== filterdate && item["completed"]==null}) /more code to insert data in spreadsheet` – Sheils Apr 25 '19 at 08:42
  • Inspired by you advise I am having a relook at my codes and making some changes. Code moving along a bit but I am not out of the woods yet. Will add further comments after modification and testing have completed. Or if you wish I can close this question aware you the point and post separate question noting that your advise has already put me on the right path – Sheils Apr 25 '19 at 09:24
  • @Sheils Thank you for replying. I apologize for the inconvenience. In my environment, I could confirm that the flow of my answer worked. So I think that there might be other issues. So I would like to confirm about it. If I found the clear reason, I would like to report it. So in the current stage, I would like to remove my answer once, because I don't want to make other users confuse.I apologize I couldn't find your issue soon. – Tanaike Apr 25 '19 at 12:09
0

Run your scripts as webapps that are always run as you. As far as I know tasks doesn't allow sharing or let you manipulate other peoples tasks.

J. G.
  • 1,922
  • 1
  • 11
  • 21
  • I did try publishing the spreadsheet as a webapp but it looks like it is published read only. I'd like to avoid having to create html forms and javascript to transfer the tasks. If it is possible to publish the spreadsheet read/write that would be great – Sheils Apr 25 '19 at 05:25
  • So your app has a function which updates a task and it works if you run it but not if someone else does? "read only" in this context should just mean they can't modify the app, but you don't want them to modify the app, you want them to be able to view and modify the tasks – J. G. Apr 25 '19 at 17:48
  • Hi J.G, Following Tanaike confirmation test I have concluded that it was possible to use the spreadsheet to update my task from the spreadsheet when opened in another users account. After some cleaning up all the functions triggered by onEdit (Installed) is working fine. The only problem that I am still having is to get the code to fetch a list of task when a button is clicked on the spreadsheet. The code works fine when called by a function in the standalone script trigger by onEdit but not when called by function in bounded sheet triggered by the button. The code itself is in the standalone – Sheils Apr 25 '19 at 19:27