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. You can use client-side scripting for the lifecycle state transition event by adding something similar to the following under the datamodel element.
<data name="transitionScripts"> <!--name - defines that this element contains the set of transition scripts. It is required to be set to 'transitionScripts'--> <js forEvent=""> <!--forEvent - defines the event that this script block will execute--> <console function=""> <!--function - defines the name of the function--> <script type="text/javascript"> <!--contains the script--> </script> </console> <server function=""> <script type="text/javascript"></script> </server> </js> </data>
Following is an example of how to make a redirection after a "Promote" is done 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.DefaultLifeCycle"> <configuration type="literal"> <lifecycle> <scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initialstate="Development"> <state id="Development"> <datamodel> <data name="checkItems"> <item name="Code Completed" forEvent=""> <!--<permissions> <permission roles=""/> </permissions> <validations> <validation forEvent="" class=""> <parameter name="" value=""/> </validation> </validations>--> </item> <item name="WSDL, Schema Created" forEvent=""> </item> <item name="QoS Created" forEvent=""> </item> </data> <!--<data name="transitionValidation"> <validation forEvent="" class=""> <parameter name="" value=""/> </validation> </data> <data name="transitionPermission"> <permission forEvent="" roles=""/> </data>--> <data name="transitionScripts"> <js forEvent="Promote"> <console function="doPromote"> <script type="text/javascript"> doPromote = function() { window.location = unescape("../listService/service.jsp?region=region3%26item=governance_list_services_menu"); } </script> </console> </js> </data> </datamodel> <transition event="Promote" target="Tested"/> </state> <state id="Tested"> <datamodel> <data name="checkItems"> <item name="Effective Inspection Completed" forEvent=""> </item> <item name="Test Cases Passed" forEvent=""> </item> <item name="Smoke Test Passed" forEvent=""> </item> </data> </datamodel> <transition event="Promote" target="Production"/> <transition event="Demote" target="Development"/> </state> <state id="Production"> <transition event="Demote" target="Tested"/> </state> </scxml> </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. Select all the check-boxes, and click on the "Promote" button. See Managing Lifecycle.
You will be redirected to the Service list. You can add any valid executable JavaScript to perform the task you require.