I need to validate that properties are filled in on the item and it’s relationships before user approves it to the next workflow step.
I managed to validate fields on the item and verify that relationships have been added, but have difficulties getting properties from the relationship. Here is the method. Also please let me know if there is an easier way to get item from the workflow other than with AML statement.
' HISTORY
' Yelena Kupershtok 05.14.2009 initial release
' ================================================================
'System.Diagnostics.Debugger.Break()
'This methods validates that the properties on RFQ Item are populated (not null) when the user attempts to
'set the RFQ's workflow state to 'Submitted'
'it also validates that Plant Feasibility has
Dim inno As Innovator = Me.newInnovator()
Dim activityID As String = Me.getID()
Dim AML As String
AML += "<AML>"
AML += "<Item type=" + """RFQ""" + " action=" + """get""" + ">"
AML += " <Relationships>"
AML += " <Item type=" + """Workflow""" + " action=" + """get""" + ">"
AML += " <related_id>"
AML += " <Item type=" + """Workflow Process""" + " action=" + """get""" + ">"
AML += " <Item type=" + """Workflow Process Activity""" + " action=" + """get""" + ">"
AML += " <Item type=" + """Activity""" + " id="+ """" + activityID+ """" + " action=" + """get""" +">"
AML += " </Item>"
AML += " </related_id>"
AML += " </Relationships>"
AML += "</AML>"
Dim q = inno.applyAML(AML)
If (q.isError()) Then
Return inno.newError("Failed to get Action Log Item for this Activity")
Else
If (IsNothing(q.getProperty("diameter"))) Then Return inno.newError("<b>Diameter</b> field is required.<br>You must provide a value for this field to submit the PAR.")
If (IsNothing(q.getProperty("width"))) Then Return inno.newError("<b>Width</b> field is required.<br>You must provide a value for this field to submit the PAR.")
'=========================================
'=======more fileds validations here
'=======verify that Plant Feasibility has 1 or more records
Dim rpf As item = q.fetchRelationships("RFQ Plant Feas REL")
Dim ppf As item = rpf.getRelationships("RFQ Plant Feas REL")
If ppf.getItemCount() = 0 Then Return inno.newError("Initial data for <b>Plant Feasibility</b> tab is required.<br>You must provide required information to submit the PAR.")
'======verify that Customer Specifics has 1 or more
'======Customer locations
Dim rpc As item = q.fetchRelationships("RFQ Customer Specific REL")
Dim ppc As item = rpc.getRelationships("RFQ Customer Specific REL")
Thanks for your help
Yelena
Disclaimer: I just wrote this using Notepad, I did not have time to do a syntax check or to run a test.
In general, anything you can write in AML can also be written using the Innovator Object API
'First define items that will get each itemtype we must access'For each item we will select just the id, so that Innovator will not'return unnecessary fieldsDim rfqItem As Item = myInnov.newItem("rfq","get")rfqItem.setProperty("select","id")
Dim wfItem As Item = myInnov.newItem("Workflow","get")wfItem.setProperty("select","id")
Dim wfProcess As Item = myInnov.newItem("Workflow Process","get")wfProcess.setProperty("select","id")
Dim wfProcAct As Item = myInnov.newItem("Workflow Process Activity","get")wfProcAct.setProperty("related_id",activityID) 'This will supply the SQL Where criteriawfProcAct.setAttribute("select","id")
'No need to access the Activity, unless there is something we need from it
'So now add these 'get' items as Relationships
wfProcess.addRelationship(wfProcAct)
wfItem.addRelationship(wfProcess)
rfqITem.addRelationship(wfItem)
'Before executing the query, also add 'get' for the RFQ Plant Feas RELDim rfqPlantFeasRel As Item = myInnov.newItem("RFQ Plant Feas REL","get")rfqPlantFeasRel.setAttribute("select","id, related_id(field1, field2)") 'I just assumed that field1 and field2 are on the related record
rfqItem.addRelationship(rfqPlantFeasRel)
'Before executing the query, also add 'get'for the RFQ Customer Specific RELDim rfqCustSpecRel As Item = myInnov.newItem("RFQ Customer Specific REL","get")rfqCustSpecRel.setAttribute("select","id, related_id(field3, field4)") 'I just assumed that field3 and field4 are on the related record
rfqItem.addRelationship(rfqCustSpecRel)
'Everything we need has been added to rfqItem'Execute the QueryDim rfqItemFind As Item = rfqItem.apply()
'No testing as to whether the query return any records, for this sample I will assume that it did
'Below reqPlantFeasItems and rfqCustSpecITems will be collections of items'So you would have to loop through them to access properties from each item
'I assume RFQ Plant Feas is the child item type in the RFQ Plant Feas RelDim rfqPlantFeasItems As Item = rfqItemFind.getItemsByXPath("//Item[@type='RFQ Plant Feas']")
Dim rfqCustSpecItems As Item = rfqItemFind.getItemsByXPath("//Item[@type='RFQ Customer Specific']")
Terry Stickel, PDM Consultant
TStickel Consulting
Sanibel, Florida
Hello Terry,
Here what I wrote based on your example
Dim myInnov As Innovator = Me.newInnovator()Dim rfqItem As Item = myInnov.newItem("rfq","get")rfqItem.setProperty("select","id")
Dim wfProcAct As Item = myInnov.newItem("Workflow Process Activity","get")wfProcAct.setProperty("related_id","activityID") 'This will supply the SQL Where criteriawfProcAct.setAttribute("select","id")
Dim rfqPlantFeasRel As Item = myInnov.newItem("RFQ Plant Feas REL","get")rfqPlantFeasRel.setAttribute("select","id, related_id(state)")
Dim rfqItemFind As Item = rfqItem.apply()
'RFQ Plant Feasibility is the child item type in the RFQ Plant Feas RelDim rfqPlantFeasItems As Item = rfqItemFind.getItemsByXPath("//Item[@type='RFQ Plant Feasibility']")Dim i As IntegerDim pfs_state As StringDim pfs_state_found As StringFor i = 0 To rfqPlantFeasItems.getItemCount() - 1pfs_state=rfqPlantFeasItems.getItemByIndex(i).getProperty("state","")If pfs_state="Quote Review" Then pfs_state_found="yes"NextIf pfs_state_found <> "yes" Then Return myInnov.newError("At lease one <b>Plant Feasibility</B> must be in the <b>Quote Review</b>state<br>before RFQ can be sent to the Customer.")
This method executed as a Pre Method on the Workflow Map path an d I am getting error "Workflow Item type does not have is_relationship=1"
What did I do wrong?
Thanks for your help,
Yelena,
There are a couple of issues:
1. In your statement, wfProcAct.setProperty("related_id","activityID") , you put "activityID" instead of just activityID.
2. It turns out that the Workflow item is not a typical relationship item, even though it has a source_id and related_id. So instead of the statement wfitem.setRelationship(wfProcess) that was in my code sample, you must use wflitem.setRelatedItem(wfProcess)
3. Finally, in my code sample a couple of times I used setProperty("select","id"), but select is an attribute instead of a property. So you must use setAttribute("select","id"). This did not cause the queries to fail, they would just return the value for many more properties than you would want
Hope that this helps
Terry,
I changed the statement for wfProcAct.setProperty to
wfProcAct.setProperty("related_id",ActivityID)
I am getting
Exception in server-side method RFQ On Before Sent to Customer (Type is VB) :Details in 7 temporary filesD:\Innovator\Innovator\Server\dll\aulb7v20Line number 18, Error Number: BC30451, Name 'ActivityID' is not declared.
Should it be wfProcAct.setProperty("related_id",wfProcAct) instead?
Thanks again for your help
In your original code (at the top of this Thread), you included the statement:
That statement is still required to provide the search value for activityID
Thanks Terry. It works great now.