Archive for the ‘formAPI’ Category

The allowed element inside text, textarea, select, radio, checkbox, readonly and hidden works fine on datacapture forms within forms publisher. Whenever a workflow instantiation form uses the allowed element, it’s not using it to use the instance designed by it.

<item pathid=”somepath” name=”somepath”>
<text>
<allowed><cred role=”master” /></allowed>
</text>
<readonly />
</item>

This snippet of XML should have allowed masters to edit the field and anyone else would just be able to look at it without modifying it. Though this works fine in forms publisher, the workflow engine’s rendition does not concern itself with such authorisation.

Instead, formAPI has to be used. To find out the current user’s name, group and roles, we can use the IWDatacapture’s getUser(), getGroups() and getRoles() methods and show or hide the fields as we please.

getUser() returns the short username (not “Laurent Picquet” but “lpiquet”), getGroups() returns an array of group names the current user belongs to and getRoles() returns an array of roles the current user has in the the current branch (“admin,master” in my case).

var roles = IWDatacapture.getRoles();
 var isMaster=false;
 for (var i in roles){
 if (roles[i]=='master'){
 isMaster=true;
 }
 }
 prompt("isMaster",isMaster);

The workflow preProcessor has access to the workflow variables. For this, we can retrieve the list of global configurable variables and datasources.

/* Configurable variables, Datasource variable and System variables */ 
Iterator<String> workflowParametersIterator = workflow.getParams().keySet().iterator(); 
while (workflowParametersIterator.hasNext()) {
 String parameter = workflowParametersIterator.next();
 System.out.println(parameter + "=" + (String)workflow.getParams().get(parameter));
}
Variable Description
$IW_HOME the installation directory of the current teamsite implementation
$IW_USER the user name of the current user
$IW_AREAOWNER the user name of the owner of the current workarea
$IW_WFNAME the name of the workflow
$IW_SESSION the session id. Very usefull for creating a new client to teamsite, with the same user as the user starting the workflow.
$IW_WORKAREA the name of the current workarea
$IW_FILES the list of attached files
$IW_TIME the current time
$IW_BRANCH the name of the current branch
$IW_STORE the name of the current content store
$IW_SERVER the name of the current teamsite server
IW_PROCESS Indicating the kind of process (PreProcessorCommand)

You can also modify the value of your configurable variables BEFORE the workflow gets started, by adding to the map of keys and values, or modifyinmg specific keys.

workflow.getParams().put("someConfigVar", "someValue");

For select options, create only one variable and use a semi-colon as a separator. On the custom instantiation form, Add some formAPI code to split the value on “;”, loop through the result and add the option to another custom variable. Make the original variable hidden.

The following example retrieves a list of “inline resources” and lets the user decide if they should be included or not by the subsequent workflow:

/* loop through the inline resources (hidden) and add the options for the attached inline resources (visible select) */  
var inlineResourcesToAttachItem = IWDatacapture.getItem("/Config/inlineResourcesToAttach");  
var inlineResourcesValue = IWDatacapture.getItem("/Config/InlineResources").getValue();  
var inlineResources = inlineResourcesValue.split(";");  
for (var inlineResourceIndex in inlineResources){
 /* create a new option to add to the visible inline resources to attach, selected and defaultSelected false by default */
 var option = new Option(inlineResources[inlineResourceIndex],inlineResources[inlineResourceIndex],false, false);
 inlineResourcesToAttachItem.addOption(option);
}

If you need to get connected to teamsite in the preProcessor, you can use the following method:

String sessionString=(String) workflow.getParams().get("$IW_SESSION"); 
String configFilePath = "/apps/interwoven/teamsite/cssdk/cssdk.cfg"; 
Properties localProperties = new Properties(); 
localProperties.setProperty("cssdk.cfg.path", configFilePath); 
CSLocalFactory csLocalFactory = (CSLocalFactory) CSLocalFactory.getFactory(localProperties); 
CSClient client = null; 
try {
 client = csLocalFactory.getClient(sessionString, Locale.ENGLISH, "myPreProcessorNameGoesHere", "localhost"); 
} catch (CSException ex) {
     Logger.getLogger(ComPageDCRInlineResources.class.getName()).log(Level.SEVERE, null, ex); 
}