# 1 EC9 Workflow Engine Form API

## 1 Description

> All interfaces are encapsulated in a global object **window\.WfForm**
>
> Some interfaces have scope of use, minimum KB version and whether the mobile / PC end is unique. General purpose without special indication
>
> Form field related operations, do not recommend the use of jQuery, prohibit native JS direct operation DOM structure
>
> We recommend to use ECOA 9.0 API interface, unified operation and maintenance by the product R\&D team, at the same time, only API could complete compatible mobile terminals

## 2 Mobile compatible

> WfForm object interface, compatible with new mobile EM7
>
> Since the API interface has been unified on the PC side and the mobile side, in order to reduce the development workload and later maintenance costs;
>
> Therefore EM7 the form no longer introduces *workflow\_base* table *custompage4emoble* columns as custom pages in mobile terminals, and directly introduces *custompage* columns (consistent with PC templates) as custom pages
>
> Front end (JS method) distinguishing terminal:

*WfForm.isMobile()* could be used to check whether is mobile

```javascript
var isMobile =WfForm.isMobile(); 
//true means eMobile、 WeChat, Dingtalk and other mobile device, false means PC
```

Backend requests (custom pages, etc.) detemien terminals:

```javascript
boolean isMobile = "true".equals(request.getParameter("_ec_ismobile "); 
//true means eMobile、 WeChat, Dingtalk and other mobile device, false means PC
```

## 3 Front-end Development

> Mode 1: code blocks in each layout template, individually configured on display/print/mobile templates for individual nodes
>
> Mode 2: workflow\_base table custompage, for all nodes in the current workflow, display and print and mobile\
> Note that the process may have values if associated with budgets, attendance, vehicles, etc.
>
> Mode 3: *Workflow management->Application settings->Process Form User-defined Page* for all non-template scenarios (PC and movement). Note that this page is global custompage, avoid writing global functions such as ready、checkCustomize, and define only some function bodies
>
> Special note: For Mode 2, Mode 3, prohibits use init\_wev8.js.;
>
> When the configuration does not take effect, please write the code block / custompage only alert confirmation method to check whether it takes effect, and then debug the cause of the error step by step.

## 4 PC way to open the form

> New request: System will be automatically retrieve the active workflow version base on the workflow id

```javascript
window.open("/workflow/request/CreateRequestForward.jsp?workflowid=747");
```

> View request: User must have this request view permission, the primary and secondary account acccount must be in link. The parameter is request ID

```javascript
window.open("/workflow/request/ViewRequestForwardSPA.jsp?requestid=5963690");
```

## 5 Open form link on mobile device

> Mobile form link

```javascript
// New link, the workflow id
var createUrl = "spa/workflow/forwardMobileForm.html?/ iscreate=1& workflowidiscreate=747";
// View links,  Request id
var viewUrl = "spa/workflow/forwardMobileForm.html?/ requestid=4503066";
```

> **First method** (recommended): Call the package method If the module is packaged with mobile framework, it can be called directly When it's a self-developed interface, you need to call /spa/coms/openLink.js Minimum support system version: KB900190601 openLink.openWorkflow (url, callbackFun, returnUrl)

| Parameters  | Parameter type | Remarks                                         |
| ----------- | -------------- | ----------------------------------------------- |
| url         | String         | Links to open forms                             |
| callbackFun | Function       | EM client only, callback function when returned |
| returnUrl   | String         | EM client, return/submit to specified link      |

```javascript
window.openLink.openWorkflow (createUrl,function(){
 alert ("E-mobile opens the form link and triggers this callback function after return/submit");
});
// Non-EM open, return/submit then back to the process center
window.openLink.openWorkflow(createUrl,null,"/spa/workflow/static4mobile/index.html#/center/doing");
```

> **Second Method**: EM client only, open the form and control the return/submission event callback\
> Use of EM-SDK, call webview to realize

```javascript
// Two steps, first call SDK webview, thenn call SDK control callback refresh
window.em.openLink ({
 url：viewUrl,
 openType：2
});
window.em.ready (function(){
 window.em.registerBroadcast ({
 name："_closeWfFormCallBack",
 action：function (argument){
 alert ("E-mobile opens the form link and triggers this callback function after return/submit");
      }
    });
});
```

> **Third Method**: window\.open/window\.location.href redirect \
> This way url you need to pass parameters returnUrl and transcode to specify the return/submit address.\
> If it is EM client to use mode one or mode two!

```javascript
window.open (viewUrl +"& returnUrl="+window.encodeURIComponent "/test.jsp?param1=test11&param2=test22"));
```
