0

Cannot understand why when I'm pressing the button it triggers the function multiple times. Also, the event handler handleCardClick(e) returns back whole json (instead of saying what action was triggered). Any idea on what I'm doing wrong?

function testLogic(input) {
  Logger.log("testLogic triggered" + input);
}

function buildCategoryCardV2(categories) {
  const buttons = categories.map(category => ({
    text: category,
    onClick: {
      action: {
        function: testLogic(category),
        actionMethodName: 'showCategory', 
        parameters: [{ key: 'category', value: category }]
      }
    }
  }));
  const card = {
    cardId: 'category_selector',
    card: {
      name: 'Category Selector',
      header: { title: 'Inventory Request', subtitle: 'Please select a category' },
      sections: [{ widgets: [{ buttonList: { buttons: buttons } }] }]
    }
  };
  return card;
}

logger_screenshot

1 Answer 1

1

Update:

This is the right syntax for the return which will tell the value of the parameter:

e.commonEventObject.parameters

And correct syntax for the function:

function buildCategoryCardV2(categories) {
  const buttons = categories.map(category => ({
    text: category,
    onClick: {
      action: {
        "function": "handleCardClick",
        "parameters": [
        // Pass the variable's value as a parameter
        { "key": "categoryPressed", "value": category } 
      ]
      }
    }
  }));
  const card = {
    cardId: 'category_selector',
    card: {
      name: 'Category Selector',
      header: { title: 'Inventory Request', subtitle: 'Please select a category' },
      sections: [{ widgets: [{ buttonList: { buttons: buttons } }] }]
    }
  };
  return card;
}
Sign up to request clarification or add additional context in comments.

Comments

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.