Workflow Examples

This topic provides an example of a process XML, html webform for manual step, and a CWF program.

Process XML

<?xml version="1.0" encoding="UTF-8"?>

<!-- Process definition -->

<Process name="Vacation_Request">

<StartTask>

<variables>

<variable>Employee name</variable>

<variable>Vacation start date</variable>

<variable>Vacation end date</variable>

</variables>

<start_step>_11E46E20-1111-4A5B-AB56-9A86DEAFBAF1</start_step>

</StartTask>

<!-- auto step to queue the document for Manager approval -->

<AutoTask id="_11E46E20-1111-4A5B-AB56-9A86DEAFBAF1" name="Queue for approval">

<cwf_name>wf_VR_initial</cwf_name>

<cwf_params>debug unique</cwf_params>

<steps>

<step name="default">_13A1B753-2222-4163-8E9F-35EA04238397</step>

<!-- approval by Manager 1-->

<step name="mgr 2 approval">_14A1B753-3333-4163-8E9F-45EA04231400</step>

</steps>

</AutoTask>

<!-- approval/rejection by Manager 1 -->

<ManualTask id="_13A1B753-2222-4163-8E9F-35EA04238397" name="Manager 1 approval">

<recipient>Manager_1</recipient>

<webform>{FORM_NAME_approval_1}</webform>

<steps>

<step name="timeout" minutes="10080">_19C9267A-6666-4D22-B5E6-0E9C28BFCBCE</step>

<step name="default">_153B16DA-4444-49BF-8697-9A86DEAFBAF3</step>

</steps>

</ManualTask>

<!-- approval/rejection by Manager 2 -->

<ManualTask id="_14A1B753-3333-4163-8E9F-45EA04231400" name="Manager 2 approval">

<recipient>Manager_2</recipient>

<webform>{FORM_NAME_approval_2}</webform>

<steps>

<step name="timeout" minutes="10080">_19C9267A-6666-4D22-B5E6-0E9C28BFCBCE</step>

<step name="default">_153B16DA-4444-49BF-8697-9A86DEAFBAF3</step>

</steps>

</ManualTask>

<!-- send ‘approved’ or ‘rejected’ document to Employee's Inbox -->

<AutoTask id="_153B16DA-4444-49BF-8697-9A86DEAFBAF3" name="process - send document">

<cwf_name>wf_VR_process</cwf_name>

<cwf_params>debug unique</cwf_params>

<steps>

<step name="default">_1A3B16DA-AAAA-49BF-1297-9A8FDEAF3AF3</step>

</steps>

</AutoTask>

<!-- vacation request rejected - send ‘rejected’ document to Employee's Inbox -->

<AutoTask id="_17C9267A-5555-4D22-B5E6-0E9C28BFCBCE" name="rejected">

<cwf_name>wf_VR_reject</cwf_name>

<cwf_params>debug unique</cwf_params>

<steps>

<step name="default">_1A3B16DA-AAAA-49BF-1297-9A8FDEAF3AF3</step>

</steps>

</AutoTask>

<!-- handle timeout - HR selects Recipient -->

<ManualTask id="_19C9267A-6666-4D22-B5E6-0E9C28BFCBCE" name="timeout">

<recipient>HR</recipient>

<webform>{FORM_NAME_timeout}</webform>

<steps>

<step name="default">_123B16DA-7777-49BF-8697-9A86DEAFBAF1</step>

</steps>

</ManualTask>

<!-- send ‘timeout’ document to Recipient's Inbox -->

<AutoTask id="_123B16DA-7777-49BF-8697-9A86DEAFBAF1" name="HR - send document">

<cwf_name>wf_VR_HR_send_doc</cwf_name>

<cwf_params>debug unique</cwf_params>

<steps>

<step name="default">_1A3B16DA-AAAA-49BF-1297-9A8FDEAF3AF3</step>

</steps>

</AutoTask>

<!-- finish -->

<FinishTask id="_1A3B16DA-AAAA-49BF-1297-9A8FDEAF3AF3"/>

</Process name>

Webform for Manual Step

<html>

<head>

<style>

.centered {

margin: auto;

width: 20%;

border: 3px solid green;

padding: 10px;

}

</style>

</head>

<body leftmargin="0" topmargin="0" >

<div class="centered wf_process_manual_task_var" id="Employee name">

</div>

<div class="centered">

<p class="wf_process_manual_task_var" id="Vacation start date"> </p>

<p class="wf_process_manual_task_var" id="Vacation end date"> </p>

</div>

<div class="centered">

<form id="wf_process_manual_task_form">

<input type="radio" name="disposition" value="approved"> Approve<br>

<input type="radio" name="disposition" value="rejected"> Reject<br>

</form>

</div>

</body>

</html>

CWF Program

${set list}

program wf_VR_process : int

( var param_count : int,

var param_ary[] : string

)

{

var instance_id : u_int; // Instance ID passed in

var dvname : string; // DocuVault name

var wf : workflow; // Workflow object

var emp_name : string; // employee name

var start_date : string; // starting date

var end_date : string; // end date

var disposition : string; // "approved" or "rejected" disposition

var sxml : file; // Spruce XML data file

var sxml_file_title : string; // Spruce XML data file title

var spr : spruce; // Spruce object

var sdlist : doc_list; // Spruce crested doc list

var recip_query : string; // recipient routing query

var ral : recip_addr_list; // recipient list returned from query

var dt : dtic; // DTic to queue to inbox

// validate execution type

if param_count != 2 then

{

message("This program can only be run as a Workflow task\r\n");

return(1);

}

if param_ary[0] != "Cypress_Workflow" then

{

message("This program can only be run as a Workflow task\r\n");

return(2);

}

 

// initialize

if not connect_local_vault() then

{

message("Error connecting to DocuVault\r\n");

message(get_last_result_text());

wf.set_history("Error connecting to DocuVault", workflow_action_error_v);

return(5);

}

dvname := get_local_vault_name();

instance_id := U_INTEGER(param_ary[1]);

if not wf.load_instance() then

{

message("Error loading instance information\r\n");

message(get_last_result_text());

wf.set_history("Error loading instance information", workflow_action_error_v);

return(10);

}

// get variables and validate their values

emp_name := wf.get_wf_variable("Employee name");

if emp_name = "" then

{

message("Error - 'Employee Name' variable not set\r\n");

wf.set_history("Error - 'Employee Name' variable not set", workflow_action_error_v);

return(30);

}

start_date := wf.get_wf_variable("Vacation start date");

if start_date = "" then

{

message("Error - 'Vacation start date' variable not set\r\n");

wf.set_history("Error - 'Vacation start date' variable not set", workflow_action_error_v);

return(35);

}

end_date := wf.get_wf_variable("Vacation end date");

if end_date = "" then

{

message("Error - 'Vacation end date' variable not set\r\n");

wf.set_history("Error - 'Vacation end date' variable not set", workflow_action_error_v);

return(40);

}

disposition := wf.get_wf_variable("disposition");

if disposition = "" then

{

message("Error - 'disposition' variable not set\r\n");

wf.set_history("Error - 'disposition' variable not set",

workflow_action_error_v);

return(50);

}

if disposition != "approved" and disposition != "rejected" then

{

message("Error - 'disposition' variable does not contain 'approved' or 'rejected'\r\n");

wf.set_history("Error - 'disposition' variable does not contain 'approved' or 'rejected'", workflow_action_error_v);

return(55);

}

message_dbg("Employee name = '" + emp_name + "'; Start date = '" + start_date

+ "'; End date = '" + end_date + "'; Disposition = " + disposition + "\r\n");

// create Spruce input file

if not sxml.open("WF_Vac_spruce_data.xml", "w") then

{

message("Error - creating Spruce data XML file\r\n");

message(get_last_result_text());

wf.set_history("Error - creating Spruce data XML file", workflow_action_error_v);

return(80);

}

sxml_file_title := sxml.get_full_file_title();

// create Spruce input file

sxml.write_line("<?xml version=\"1.0\" standalone=\"no\" ?>");

sxml.write_line("<input>");

sxml.write_line(" <global></global>");

sxml.write_line(" <document>");

sxml.write_line(" <emp_name>" + emp_name + "</emp_name>");

sxml.write_line(" <vac_start_date>" + start_date + "</vac_start_date>");

sxml.write_line(" <vac_end_date>" + end_date + "</vac_end_date>");

sxml.write_line(" </document>");

sxml.write_line("</input>");

sxml.close();

// run Spruce to create the approved/rejected document

spr.initialize(dvname);

spr.set_input(sxml_file_title);

if disposition = "rejected" then

spr.set_template("WF.Vac_reject");

else

spr.set_template("WF.Vac_approve");

if not spr.execute(sdlist) then

{

message("Error - Executing Spruce to create output document\r\n");

message(get_last_result_text());

wf.set_history("Error - Executing Spruce to create output document", workflow_action_error_v);

return(100);

}

sxml.delete(sxml_file_title); // remove input file

message_dbg("approved document document created by Spruce\r\n");

doc := sdlist.get_first_document();

// store document into DocuVault

doc.set_doc_title("Vacation request " + disposition);

if not doc.create_new_document(dvname, plex_original_v) then

{

message("Error creating document\r\n");

message(get_last_result_text());

wf.set_history("Error creating document", workflow_action_error_v);

return(120);

}

message_dbg("document created - " + string(doc.get_ddoc_id()) + "\r\n");

// attach document to Workflow process

wf.add_document(doc, "Vacation request " + disposition);

// Queue document to inbox

recip_query:= "select inbox from DV(\"" + dvname + "\") where loc([name] =

\"" + emp_name + "\")";

message_dbg("recipient query = '" + recip_query + "\r\n");

ral.query_recip_addr(recip_query);

dt.set_dtic_document(doc);

dt.set_dtic_name("Vacation request");

dt.set_dtic_subject("Vacation request " + disposition);

if not ral.send_dtic(dt) then

{

message("Error sending document to recipient\r\n");

message(get_last_result_text());

wf.set_history("Error sending document to recipient", workflow_action_error_v);

return(140);

}

wf.set_history("document created and delivered", workflow_action_send_v);

message_dbg("Program complete\r\n");

return(0);

}