- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
I haven't had my hands in code for a while so I was looking for a reason to have a good ol' fashion geeky relapse. This past week one of my favorite customers (ok, so they're all my favorite) gave me that opportunity. They asked about using the workflow field for a use that didn't have anything to do with an automated workflow, a custom data driven workflow field.
They wanted to display the standard workflow stage widget but have the stages custom built from data related to each record. I didn't know off the top of my head so I did a little digging and came up with the following.
Here's my sample use case.
As a project manager…. (yeah, I've been a PO for almost a year now so I actually start all my sentences in this form)
I would like to display a summary of who the project reviewers are for a given project and what the state of their review is (requested, completed, not needed). Each project could have unique reviewers and reviewer states. This information should be visible in the project list view.
Solution:
We could solve this a number of ways including possibly using a real workflow and approvals, but in order to show you how generic this could be I avoided both of those. Plus, the customer already has the related data populated so they'd be able to just start displaying it instead of having to migrate data to a new structure.
What's needed:
Data - let's start by creating the table that will be used to drive the workflow widget values
* Table name: u_project_review
* Field: u_project, reference to pm_project
* Field: u_reviewer, reference to sys_user
* Field: u_state, choice (drop down w/none)
* Add choices to u_state (Requested, Completed, Not Needed)
New workflow field on Project (pm_project) table
* Field: u_review_status, type=workflow, choice=drop down w/none, set to read only since it's managed dynamically
* Add this field to the project list view
Logic
Now we need a way to drive the workflow field list widget from the related project reviewer data.
* Create New Business Rule
* Name (must be precise based on table and field names) = pm_project_u_review_statusGetChoices
* Table: global
* Active: true
* Script:
//build a dynamic workflow field choice list based on related data
//this function will be called by the workflow field during rendering
function pm_project_u_review_statusGetChoices() {
//get related project review records for this project (current)
var gr = new GlideRecord("u_project_review");
gr.addQuery("u_project", current.getUniqueValue());
//probably want to set an order that makes sense to you, we'll use reviewer
gr.orderBy("u_reviewer");
gr.query();
if (!gr.hasNext()) {
//no reviewers show let it be known
answer.add("not_needed", gs.getMessage("No reviewers needed")).image = "images/workflow_complete.gifx";
}
while (gr.next()) {
//set default icon to pending
var icon = "images/workflow_pending.gifx";
var text = "Requested";
//set other image based on state value
var stateValue = gr.getValue("u_state");
if (stateValue == "Completed") {
icon = "images/workflow_complete.gifx";
text = "Complete";
}
else if (stateValue == "Not Needed") {
icon = "images/workflow_skipped.gifx";
text = "Not Needed";
}
//build text for choice label
var display = gr.getDisplayValue("u_reviewer") + " (" + text + ")";
//add the choice to the list, and set the icon
answer.add(gr.getUniqueValue(), display).image = icon;
}
}
Reviewer Data
* Add the project review related list to the project form
* Go ahead and create some project reviewer records with valid project, reviewer, and state values.

And we're done
Checkout the project list now that we have values
Other thoughts….
The field value of u_review_status doesn't really make sense at all since it's a collection of data, for that reason I would leave the field off the form and not use it for reporting (it doesn't really have a value stored in the record at this point). I'm sure there's plenty of clever folks out there that could take this to the next level. My $0.02, I'd have the updating of project review records set the actual value of the review status field on project, this would be a summary of all reviewer states. This value would be completely independent from the rendering of the workflow widget.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.