Javascript
his kind of subscription is the most generic. It enables you to really control the document. It is the best subscription type to perform computations between the fields and allocate several fields of the document.
Here is an example enabling to achieve a total on a dynamic table column:
<script event="onChange" for="DetailDeLaNote" on-stage="DemandeDeRemboursement"><![CDATA[
var total = 0;
var resources = iWorkflowModule.getLinkedResources(iWorkflowInstance,"DetailDeLaNote");
if( resources!=null ) {
for( var it=resources.iterator(); it.hasNext(); ) {
var value = it.next().getValue("Cout");
if( value!=null ) {
total += value.floatValue();
}
}
}
iWorkflowInstance.setValue("MontantTotal",new java.lang.Float(total)); ]]>
</script>
Tags
Script
The “script” element defines the subscription input in XML of the resource template.
Element | Description |
---|---|
event | Name of occurred event The possible values are: onLoad, onChange. |
for | Document fields, separated by comas, modified and trigger of the “onChange” event. |
on-stage | Names of the steps on which the treatment must process. The keyword “sys_CreationWizard” enables to indicate that the treatment will be processed only on the action of process document creation. |
It is highly recommended to use the < ![CDATA[…]]
tags to surround the Java Script code and then avoid to make XML syntax errors
The SDK API are available when processing the JavaScript subscriptions.
The API keywords available in JavaScript
Key word | Description |
---|---|
iWorkflowModule | IWorkflowModule is the module of workflow of Process |
iContext | IContext is the context of the connected user |
iUser | IUser is the connected user |
iWorkflowInstance | IWorkflowInstance represents the current document |
iTaskInstance | ITaskInstance is the active task of the current document |
iAction | IAction corresponds to the action at the step change. |
iResourceController | IResourceController is a controller which permits to dynamically modify the graphical aspect of a resource. It permits to specify that the fields of a resource may be edit, hide, compulsory or in error. |
The IDocumentExtension4 interface
The IDocumentExtension4 interface has been implemented in the Process JavaScript. It is then possible to use every function of this interface as “callback”.
To use these “callback”, you don’t need to define every of them in the resource template administration. You just need to define only one function that you don’t want to use.
Example of implementing the methods of the IDocumentExtension4 interface : in this example, every function is defined. They have all a “log” instruction that permits to log the calls order:
<script>
log.info("script initialization");
function onBeforeLoad() {
log.info("onBeforeLoad()");
return true;
}
function onAfterLoad() {
log.info("onAfterLoad()");
return true;
}
function isChangeSubscriptionOn( field ) {
log.info("isChangeSubscriptionOn("+field.getPropertyName()+")");
return false;
}
function onFieldChanged( field ) {
log.info("onFieldChanged("+field.getPropertyName()+")");
}
function onBeforeSave( checkMandatory ) {
log.info("onBeforeSave("+checkMandatory+")");
return true;
}
function onAfterSave() {
log.info("onAfterSave()");
return true;
}
function onBeforeSubmit( actionKey ) {
log.info("onBeforeSubmit()");
return true;
}
function onAfterSubmit( actionKey ) {
log.info("onAfterSubmit()");
return true;
}
function onBeforeClose() {
log.info("onBeforeClose()");
return true;
}
function onBeforeAbort() {
log.info("onBeforeAbort()");
return true;
}
function onBeforeRemind() {
log.info("onBeforeRemind()");
return true;
}
function onBeforeCancelDelegation() {
log.info("onBeforeCancelDelegation()");
return true;
}
function onAfterCancelDelegation() {
log.info("onAfterCancelDelegation()");
return true;
}
function onBeforeRefuseDelegation() {
log.info("onBeforeRefuseDelegation()");
return true;
}
function onAfterRefuseDelegation() {
log.info("onAfterRefuseDelegation()");
return true;
}
function onBeforeDelegate() {
log.info("onBeforeDelegate()");
return true;
}
function onAfterDelegate() {
log.info("onAfterDelegate()");
return true;
}
function onBeforeDelegateTaskOnly() {
log.info("onBeforeDelegateTaskOnly()");
return true;
}
function onAfterDelegateTaskOnly() {
log.info("onAfterDelegateTaskOnly()");
return true;
}
function onBeforeSendInformation() {
log.info("onBeforeSendInformation()");
return true;
}
function onAfterSendInformation() {
log.info("onAfterSendInformation()");
return true;
}
</script>
Example of initializing a user field (in this example, the script is executed on the creation step):
<script on-stage="sys_CreationWizard"><![CDATA[
function onAfterLoad() {
iWorkflowModule.setExternalUser(iWorkflowInstance, "Utilisateur", iUser);
}
]]></script>