Actions are one of the most common ways users interact with data in Aras, whether from the main grid, item forms, or main menu. While creating custom actions is fairly straightforward, creating multi-select item actions requires the use of a built-in method called PE_GetSelectedItems. This post demonstrates how to use PE_GetSelectedItems to implement a multi-select item action that copies property data from the selected items to the clipboard.
The code shown below is part of the Copy to Clipboard Aras Community Project. If you want to apply the project or view the source code in its entirety, you can find it on the Aras Labs GitHub:
copy-to-clipboard – Contains sample code to demonstrate how to copy text to the clipboard in an Aras client-side action.
The PE_GetSelectedItems Method
The PE_GetSelectedItems method is part of the Aras Product Engineering application. It’s included in every InnovatorSolutions database (the default database option in the Aras Innovator installer). On a high level, the PE_GetSelectedItems gets all the selected items, whether from a relationship grid, main grid or form, and returns a collection of the selected items.
Check out the PE_AddToChange action for a built-in Aras action that uses PE_GetSelectedItems.
Creating the ‘Item to Clipboard’ Method
The method we need for the Copy to Clipboard action can be broken into three basic steps. First, we need to get the collection of items passed into the method from PE_GetSelectedItems.
Next we need to loop through the collection of selected items and build a string from the items’ property data. In the sample code provided in the Copy to Clipboard project, we use the item_number and name properties from Part. Be sure to update the properties referenced in the method if plan to use the action with another ItemType.
Now that we’ve built a string containing the data we want to copy, we can use a couple helpful functions provided by the Aras Innovator client. Not all browsers allow programmatic access to the clipboard, so we’ll use the aras.utils.isClipboardSupported() function to check.
If clipboard access is permitted, we will use the copyToBuffer() function shown below. This function is based on the code behind the Copy ID button in the item properties dialog. If our current browser does not allow access to the clipboard, we will output the data in an alert dialog so users can manually copy it.
Creating the Action
The Copy to Clipboard action requires the following properties to work as a multi-select item action. Other properties (name, label, target, etc.) can be set to fit your use case.
- Type: Item
- Location: Client
- Method: PE_GetSelectedItems
- On Complete: Item to Clipboard
The “method” property must be set to PE_GetSelectedItems in order to pass the collection of selected items to our custom method – Item to Clipboard. Without PE_GetSelectedItems, only the last selected item would be available to our method code.
Once you attach your Copy to Clipboard action to an ItemType’s Action tab, you will be able to select multiple items and copy their data to your clipboard.