Displaying Your HTML View in a Custom Activity
Workflow Form Contains:
»
A text field for every piece of data that you plan to pass back to the Workflow model
(to be saved in a context parameter).
»
A local variable that will hold your HTML view code
»
A display area that references the local parameter containing your HTML view’s code
HTML View Contains:
<style>
div.my_html_view {
position:
relative;
top:
-130px;
left:
-20px;
height:
100%;
width:
800px;
overflow:
scroll;
background-color:
White;
}
</style>
<div class=“my_html_view">
This is the content that will be displayed in place of the
Workflow fields defined in the Custom Activity Designer…<br>
<br>
I can use any HTML features I want, and use JavaScript to pass
data back to the Workflow form<br>
<br>
<input type=“checkbox” value=“Yes” id=“my_checkbox”
onclick=“my_js_function();” /> Here’s a checkbox.
</div>
Copy values between Workflow form and HTML view
Workflow Form Contains:
Text field named my_approval
Text area named my_note
Display area containing @html_view
HTML View Contains:
<select id=“my_dec”>
<option value=“Approve”>Approve</option>
<option value=“Reject”>Reject</option>
</select>
<textarea id=“my_txt”></textarea>
JavaScript Code:
<script language="javascript"> function copy_from_workflow(){var v_decision = document.forms['workItemForm'].elements['p_my_approval'].value; var v_note = document.forms['workItemForm'].elements['p_my_note'].value;
document.getElementById('my_dec').value = v_decision; document.getElementById('my_txt').value = v_note; }
function copy_to_workflow(){
var v_decision = document.getElementById('my_dec').value; var v_note = document.getElementById('my_txt').value;
document.forms['workItemForm'].elements['p_my_approval'].value = v_decision; document.forms['workItemForm'].elements['p_my_note'].value = v_note;
} </script>
HTML Code:
Hit this button to load the notes: <input type=“button” onclick=“load_notes();” /> Notes will be displayed here:
<div id=“note_container” style=“display:none;”></div>
Notes can also load automatically as page is loading:
<script language="javascript"> load_notes(); </script>
JavaScript Code:
<script language="javascript"> function cr_req_obj() {
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer")
return new ActiveXObject("Microsoft.XMLHTTP"); else
return new XMLHttpRequest(); }
var http_req = cr_req_obj(); function load_notes() {
var url_str = ‘https://<your self-service URL and port number>’; var url_str += ‘<database package>.<database procedure>’;
var url_str += ‘?<first variable>=<value>’; var url_str += ‘&<next variable>=<value>’; http_req.open(‘POST', url_str); http_req.onreadystatechange = load_notes_response; http_req.send(null); } function load_notes_response() { if (http_req.readyState == 4) {
var response = http_req.responseText; if(response.indexOf('|' != -1)) {
document.getElementById('note_container').innerHTML = response; document.getElementById('note_container').style.display='block'; }
else
alert('There was a problem with your AJAX request!'); } } </script>
SQL Code:
PROCEDURE ajax_notes IS BEGINFOR notes IN( SELECT my_notes FROM my_table ) LOOP
Form Validation
Create function to hide the Workflow “Complete” button.
Set it to run when page finishes loading:
<script language=“javascript”>
function hide_complete_button() {
var btn = document.forms['workItemForm'].elements['button_complete'];
btn.style.display='none';
}
window.onload = function(){hide_complete_button};
</script>
Validation code to check form input values:
function validate_form(){
if( … ){
alert(‘You must fix this!’);
document.getElementById(‘problem_field’).style.borderColor=’Red’;
}
else
document.forms['workItemForm'].elements['button_complete'].click();
}
Create your own “Validate Button”
“Fine Print” Regarding Code Samples
© 2011 Portland State University
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
Neither the name of Portland State University nor the names of its contributors may be
used to endorse or promote products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS