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.