Sometimes it is useful to perform actions during an install, but the actions are not part of a product that you want to permanently install into the account. For example, you might want to create a special user group.
Run once is a product pattern for achieving this. It is a special product that is installed, run, and then uninstalled, to perform one-off processing.
Run once products are easy to set up.
Node type
You need a node type for the product instance that will be executed. Use the normal Type With Scripts, and in the Script script, add the logic for the aciton you want to perform.
The script can refer to install options, as in the following example.
var context = application.getContext();
var request = application.get('request');
var installOptions = application.parseJSON(request.getString('installOptions'),{});
function main() {
// Perform action
// Optionally, delete the instance
context.deleteNode();
}
if ( !application.errorFound() ) {
main();
}
You might also want to add the Hidden in the Set Tags list and add Tag List to the Member Type List so that your product instance does not appear on the home page.
Product template
Set your product template to an instance of your node type.
Product builder
In the product builder, set the install template, and set the post install script to Execute And Uninstall Post Install Script. This will execute your product instance on install, passing it product options. Assuming the execution is successful, it will then schedule an uninstall of the product and delete of the instance using Uninstall Product Service. If the instance of the product deletes itself (which is reasonable for a run once product), Uninstall Product Service is called immediately to clean up the subscription.