How to bulk update static table records based on selected rows?

How can I bulk update records in a static table using the checkbox and the CommandMenu?

When rows are selected, I want to launch a script by using one of the options in the CommandMenu.
I didn't find any solution for getting the ID's so I can use these in my script.

See example below:

RE: How to bulk update static table records based on selected rows?

Hello,

You can get the selected records by looping through the table rows and checking if the 'Selected' variable is set to true.

Example:

HtmlElement table = getHtmlElement("exampleTable");

Integer tableRows = table.getFieldValue("numRows").toInteger();

for (Integer i = 0; i < tableRows; i++)
{
    Bool rowSelected = table.getFieldValue("row." + i.toString() + ".selected").toBool();

    if (rowSelected == true)
    {
        Integer saleId = table.getFieldValue("row." + i.toString() + ".id").toInteger();
    }
}

Based on your screenshot your processing sales, so to get the saleId of the selected rows you can set the id parameter on the addRow when filling the static table:

HtmlElement table = addHtmlElement(getScreenElementId(screenElementIndex),
  getScreenElementName(screenElementIndex),
  getScreenElementType(screenElementIndex),
  getScreenElementConfig(screenElementIndex));


table.setFieldValue("addRow", Map().insert("selected", "false").insert("id", saleId));

 

 

Af: David Hollegien 30. apr 2019

RE: How to bulk update static table records based on selected rows?

Hi David,

Where do I place the loop part?

I want to use the addCommandMenu button I've created and launch a script to update sales, like:

//Create button at the bottom of the grid
Map lostButton;
lostButton.insert("label", "Change to Lost");
lostButton.insert("url", getProgramBlogic() + "&action=doScript&idString=update_sale&saleId=" + saleId.toString());
lostButton.insert("idString", "new_button");
lostButton.insert("iconUrl", "https://online.superoffice.com/Cust20018/CS/graphics/Seven/refresh.png");

grid.setFieldValue("addCommandMenu", lostButton);
Af: Brian Mulder 30. apr 2019

RE: How to bulk update static table records based on selected rows?

Hello Brian,

Sorry, I read over the part you that want to trigger it using an command button.

Not sure how to solve it when using the command menu, you need to do a POST operation on the screen after the rows are selected to get the selected id's.

But the command menu is already initialized when loading the screen, where you don't have the selected ids.

If you add two 'normal' buttons 'Change to lost' and 'Change to sold' (using for ex. the button row element), you can retrieve the selected ids using a (button) script.

Af: David Hollegien 2. maj 2019

RE: How to bulk update static table records based on selected rows?

Hi David,

Thanks for your great input! I suppose what you are saying is that you need to use buttons such as the ones below (marked in red)?

The issue you describe is similar to the topic below?

https://community.superoffice.com/en/developer/forum/rooms/topic/superoffice-product-api-group/customer-service/adding-button-to-a-static-grid/

 

It would be useful if you could launch the "button-script" from the Actions-menu (marked in green) as well!

Af: Bas Kreijveld 2. maj 2019

RE: How to bulk update static table records based on selected rows?

Hello Bas,

Yes that is the solution that I meant. The link you provided is indeed about the same issue, that you can't directly perform an action on the selected rows from a command menu.

Af: David Hollegien 2. maj 2019