0

having a bit of a challenge when building a Google Calendar AddOn that helps us to log time against projects we are working on. The project management tool is built in Salesforce, so we are grabbing the Project records and associated Tasks (1:many) when user first starts a session with the AddOn, this is being cached in the User cache.

I am setting two picklists that are populating from a list of Projects and Tasks fetched from a remote server. The idea is that from the first drop down you select your project, then the second drop down populates with a list of tasks for that individual project.

CardService.newCardSection().addWidget(CardService.newTextInput().setSuggestions(createProjectSuggestions()).setFieldName("project").setTitle("Project"))
          .addWidget(CardService.newTextInput().setFieldName("task").setTitle("Task").setHint('Select your project first and see a list of tasks').setSuggestionsAction(buildTaskSuggestionsAction)

I can't seem to make the buildTaskSuggestionsAction fire on a change of the "project" input field? To populate this list it requires input in the text field "task", then a wait while the task list is built. Once built, the task list also doesn't filter to the input from the user.

/**
* loop through projectsAndTasks and pull project names for suggestion list
*/
function createProjectSuggestions() {
  var suggestions = CardService.newSuggestions();
  var projectsAndTasks = fetchProjectsAndTasks(); 

  var records = projectsAndTasks.records;
  for(var i in records) {
    suggestions.addSuggestion(records[i].Name);
  }
   return suggestions;
}

/**
* loop through and create task list for selected project
*/
function createTaskSuggestions(e) {

  var project = e && e.formInput['project'];
  var records = fetchProjectsAndTasks().records;

  var suggestions = [];
  for (r in records) {
    if(records[r].Name == project) {
      //TaskRay is a Salesforce plugin we are using for time tracking
      var tasks = records[r].TASKRAY__Tasks__r.records;
      for(var t in tasks) {
        suggestions.push(tasks[t].Name);  
      }
      suggestions.sort();
    }
  }
  return CardService.newSuggestionsResponseBuilder().setSuggestions(CardService.newSuggestions().addSuggestions(suggestions)).build();  
}

From what I can tell so far, there doesn't seem to be anyway to achieve this dynamic picklist behaviour? A steer in the right direction (if it exists!) would be welcome.

Thanks in advance.

Rafa Guillermo
  • 14,474
  • 3
  • 18
  • 54
  • I wouldn't do this with a Calendar add-on at all. I'm not sure about Calendar Addons but Gmail Addons don't work on Iphones. I'd do this as a standard google apps script webapp and that way anybody that has a smart phone can have access to it. – Cooper May 05 '20 at 00:32
  • Can you explain what you have tried and why it didn't work? – Rafa Guillermo May 05 '20 at 08:20
  • I have tried to attach the action to the first picklist, but that didn't seem to work.. the "why it didn't work" ... well, that is probably why I am on Stackexchange :) At the moment, I'm not sure dependent picklists are something that can be built this way .. fairly new to this world – Troy Sellers May 07 '20 at 11:28
  • @Cooper - can i ask why you wouldn't do this? Mobiles are not a platform I am targeting here (this is only going internal to our company), happy that this is always going to be browser based. – Troy Sellers May 07 '20 at 11:29
  • When you ask non specific questions you open yourself up to opinionated answers. That's my opinion.Welcome to StackOverFlow please take this opportunity to take the [tour] and learn how to [ask], [format code](https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks), [mcve] and [Tag Info](https://stackoverflow.com/tags/google-apps-script/info) – Cooper May 07 '20 at 16:30
  • Check out [this answer](https://stackoverflow.com/a/54772492/11551468) to see if it helps address your problem. – Rafa Guillermo May 08 '20 at 12:41
  • Unfortunately no. It seems like adding suggestions using [setSuggestionsAction()]( https://developers.google.com/apps-script/reference/card-service/text-input#setSuggestionsAction(Action)) stops the filtering you get when you setSuggestions on a text input widget. Even using just this code from the docs doesn't seem to work. – Troy Sellers Jun 11 '20 at 00:15

0 Answers0