Sample OnBase Workflow Script

Script to process Forms inMotion XML
XmlDocument xFIMDoc;
public void OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args) {
	string submissionID = "";
	//get the submission ID off the current document in workflow
	foreach (KeywordRecord kwr in args.Document.KeywordRecords) {
		foreach (Keyword k in kwr.Keywords) {
			if (k.KeywordType.Name == "Forms inMotion Submission ID") {
				submissionID = k.AlphaNumericValue;
				break;
			}
		}
	}
	//query for the related XML doc
	DocumentQuery d = app.Core.CreateDocumentQuery();
	d.AddKeyword("Forms inMotion Submission ID", submissionID);
	d.AddDocumentType(app.Core.DocumentTypes.Find("xml"));
	DocumentList docList = d.Execute(1);
	if (docList.Count == 0) {
		app.Diagnostics.Write("No valid XML Import file was found for this cover.  Import error");
		return;
	}
	//get the document and the content and write it to a temp file
	Document importedXml = docList[0];
	Rendition r = importedXml.DefaultRenditionOfLatestRevision;
	DefaultDataProvider prov = app.Core.Retrieval.Default;
	string outFile = Path.GetTempFileName();
	using (PageData pageData = prov.GetDocument(r)) {
		using (Stream stream = pageData.Stream) {
			Utility.WriteStreamToFile(stream, outFile);
		}
	}
	//make an XML doc and load that temp file
	xFIMDoc = new XmlDocument();
	xFIMDoc.Load(outFile);
	File.Delete(outFile);

	//header values
	DateTime completionDate = DateTime.Parse(xFIMDoc.SelectSingleNode("///FormsinMotion/header/server[@name='completiondate']").Value);

	//values from form, select by passing in the Forms inMotion form name and the name of the field on that form
	string departmentname = returnFieldText("Expense Report Form", "departmentselect");

	/*
	
	Do something useful with extracted values here
	
	*/

}

//
public string returnFieldText(string documentName, string fieldName) {
	XmlNode x;
	x = xFIMDoc.SelectSingleNode("//FormsinMotion/formPackage/form[@formname='" + documentName + "']/fields/field[@name='" + fieldName + "']");
	if (x!=null) {
		return x.Attributes["value"].Value;
	}
	else {
		return "";
	}
}