This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Client-side Scripting for Lifecycles

Each lifecycle configuration contains one or more state elements. More information on lifecycle configuration and the various elements in it, can be found in Configuring Lifecycles.

The client-side scripting support is available for lifecycle state transition event. This can be done by adding something similar to the following under the state element.

<js>
        <console promoteFunction="myFunction">
            <script type="text/javascript">
                myFunction = function() {
                    // executable script
                }
            </script>
        </console>
    </js>

Here is an example on how to add an alert for for the state transition from Initialize to Designed in the default ServiceLifeCycle.

1. Edit the existing lifecycle by adding the configuration below.

<aspect name="ServiceLifeCycle" class="org.wso2.carbon.governance.registry.extensions.aspects.ChecklistLifeCycle">
        <configuration type="literal">
            <lifecycle>
                <state name="Initialize" location="/environment/init">
                    <checkitem>Requirements Gathered</checkitem>
                    <checkitem>Architecture Finalized</checkitem>
                    <checkitem>High Level Design Completed</checkitem>
                    <js>
                        <console promoteFunction="myFunction">
                            <script type="text/javascript">
                                myFunction = function() {
                                    alert("Promoted Resource to Designed State");
                                }
                            </script>
                        </console>
                    </js>
                </state>
                <state name="Designed" location="/environment/design">
                    <checkitem>Code Completed</checkitem>
                    <checkitem>WSDL, Schema Created</checkitem>
                    <checkitem>QoS Created</checkitem>
                </state>
                <state name="Created" location="/environment/development">
                    <checkitem>Effective Inspection Completed</checkitem>
                    <checkitem>Test Cases Passed</checkitem>
                    <checkitem>Smoke Test Passed</checkitem>
                </state>
                <state name="Tested" location="/environment/qa">
                    <checkitem>Service Configuration</checkitem>
                </state>
                <state name="Deployed" location="/environment/prod">
                    <checkitem>Service Configuration</checkitem>
                </state>
                <state name="Deprecated" location="/environment/support" />
            </lifecycle>
        </configuration>
    </aspect>

2. After saving this configuration (See Adding Lifecycles), add the ServiceLifeCycle to a Service (or any other resource/collection). See Managing Lifecycle.

3. Tick all the check-boxes, and click on the "Promote" button. See Managing Lifecycle.

4. You will get an information dialog followed by the alert added.

You can add any valid executable JavaScript that is capable of performing some task that you require.