This example illustrates a Pre-job scriptlet that prevents a workflow from advancing state if a document doesn't contain certain metadata and/or XML content or attributes.
Astoria provides a review sequence scriptlet named validateStructuredDocument that can be specified in a Task Sequence document Pre-job Scriptlet field for a job transition. The method is passed a dictionary of custom attribute and XPath rules which it validates. If validation fails, an exception is thrown which prevents the workflow from changing state and feedback is provided to the user (typically via email).
Rather than specify the dictionary directly in the task sequence document, Astoria recommends that you create your own scriptlet which calls validateStructuredDocument. The scriptlet must include a step to register your scriptlet.
import registration
import starScriptlets
#Validation data resides in a dictionary where the key is a flavor on the structured document # and the value is a tuple of two tuples # tuple 1: strings of custom attribute names to be validated as not being empty # tuple 2: strings of xpath expressions not being empty g_validationDictionary = \
{\
"dita_map_map" :\
(\
("foo", "bar"),\ # tuple 1 custom attribute names for dita_map_map
("/map/@id", "/map/navtitle")\ #tuple 2: xpaths for dita_map_map
),\
"dita_map_bookmap" :\
(\
("xpnId", "xptBookTitle", "xpeImportance"),\ # tuple 1 custom attribute names for dita_map_bookmap
("/bookmap/@id", "/bookmap/booktitle", "/bookmap/booklibrary", "/bookmap/cmdname")\ #tuple 2: xpaths for dita_map_bookmap
)\
}
#############################################################################
#
# "Validates that custom attributes, elements and attributes are present and not empty"
#
def validateMyDocs(database, moduleH, job, object, currentStatus, nextStatus, isPre):
#
global g_validationDictionary
if not isPre:
return
starScriptlets.validateStructuredDocument(database, moduleH, job, object, currentStatus, nextStatus,\
isPre, g_validationDictionary)
#######################################################################################################################
#
# job review scriptlet registration
#
#######################################################################################################################
registration.registerTaskSequenceScriptlet(validateMyDocs)
In the Pre-job Scriptlet field of a state transition, you would specify:
validateMyDocs()