jbiggs - Wednesday, January 30, 2013 3:30 PM:
I have an itemtype that has a lifecyle and workflow map. When the itemtype is in a particular state, I would like to validate certain properties on the item when a user attempts to complete a workflow activity, and prevent completion when validation fails. I'm having trouble with understanding how to reference the item's properties in a method that is executed as a Pre Method in the workflow. I am new to developing in Innovator, and the only object I am familiar with referencing is the Me object, so I've tried this:
Dim status As String
Dim myi As Innovator = Me.getInnovator()
Dim e As item
status = Me.getProperty("state")
If status = "Submitted" And isnothing(Me.getProperty("snx_approvedby")) And Me.getProperty("snx_approvedby")="" Then
e = myi.newerror("<br><font color=red>You must enter an Approved Date for this Misc Credit Memo before you can complete this activity.")
Return e
End If
This doesn't work (no errors though), and I think it's because Me can't really be used because the user doesn't have the item actually open? Whatever help can be offered, I'd appreciate it!
jbiggs - Thursday, January 31, 2013 7:38 AM:
Just an FYI, I was able to get this exact code to work (sort of) when I placed it in the Lifecycle map as a Pre method instead of in the Workflow Map. However, some funkiness has resulted that I'm still trying to work out.
vasant - Thursday, January 31, 2013 9:18 AM:
Hi,
If you write method on Workflow Path (Pre Method, Post Method) then your Context will be the Activity not the Item Instance.
Means In method if you have written:
this.getProperty("id")
and the method runs from Workflow Path then it will give you id of Workflow Activity not id of Item
and the method runs from Lifecycle Transition then it will give you id of Item
So, here you have to modify your code to get Item Id from Activity Id and perform accodingly..
Hope it will be helpful..
Thanks- Vasant
jbiggs - Thursday, January 31, 2013 9:44 AM:
Thank you Vasant, that's what I thought. So the big question then is: what does the syntax look like to access an item property for a method that acts on the workflow activity? Could you provide an example?
newcomer - Thursday, January 31, 2013 10:30 AM:
The structure looks like this. I hope you are able to modify this aml statement for your needs/get the information you want.
AML += "<Item type='"+this.getProperty("itemtype","")+"' action='get' select='id'>";
AML += "<id>"+this.getProperty("itemid","")+"</id>";
AML += "<Relationships>";
AML += "<Item type='Workflow' action='get' select='related_id'>";
AML += "<related_id>";
AML += "<Item action='get' type='Workflow Process' select='id'>";
AML += "<Relationships>";
AML += "<Item action='get' type='Workflow Process Activity' select='related_id'>";
AML += "<related_id>";
AML += "<Item action='get' type='Activity' select='id,name'>";
AML += "<state>active</state>";
AML += "<Relationships>";
AML += "<Item action='get' type='Workflow Process Path' select='id,name'>";
AML += "<related_id>";
AML += "<Item action='get' type='Activity' select='id,name'>";
AML += "<name>"+this.getProperty("activityName","")+"</name>";
AML += "</Item>";
AML += "</related_id>";
AML += "</Item>";
AML += "<Item action='get' type='Activity Assignment' select='id'></Item>";
AML += "<Item action='get' type='Activity Task' select='id, is_required'><is_required>1</is_required></Item>";
AML += "</Relationships>";
AML += "</Item>";
AML += "</related_id>";
AML += "</Item>";
AML += "</Relationships>";
AML += "</Item>";
AML += "</related_id>";
AML += "</Item>";
AML += "</Relationships>";
AML += "</Item></AML>";
jbiggs - Thursday, January 31, 2013 12:25 PM:
Wow, unfortunately that's beyond my understanding right; I don't really have enough experience with AML syntax to tackle modifying that. Luckily I was able to find a way around having to do this, but in the interest of learning: is there a way to do this via VB code as opposed to AML? I'm more familiar with that language.
newcomer - Thursday, January 31, 2013 2:24 PM:
Yes, you don't have to use AML... But sometimes it's easier. So I recommed you to get familiar with it. You will also understand the concept of Aras better I guess.
When I understand your requirements correctly then the AML statement to get the item the activity belongs to looks like this:
AML += "<Item type='YOURITEMTYPE' action='get' select='YOURPROPERTIES'>";
AML += "<Relationships>";
AML += "<Item type='Workflow' action='get' select='related_id'>";
AML += "<related_id>";
AML += "<Item action='get' type='Workflow Process' select='id'>";
AML += "<Relationships>";
AML += "<Item action='get' type='Workflow Process Activity' select='related_id'>";
AML += "<related_id>";
AML += "<Item action='get' type='Activity' select='id' id='"+this.getProperty("id")+"'></Item>";
AML += "</related_id>";
AML += "</Item>";
AML += "</Relationships>";
AML += "</Item>";
AML += "</related_id>";
AML += "</Item>";
AML += "</Relationships>";
AML += "</Item></AML>";
I don't use VB so I can only give you an example in C#(pseudocode):
Item item = innovator.newItem("YOURITEMTYPE","get");
Item workflow = innovator.newItem("Workflow","get");
Item workflowProcess = innovator.newItem("Workflow Process","get");
...
Item activity = innovator.newItem("Activity","get");
activit.setProperty("id", this.getProperty("id",""));
...
workflow.setRelatedItem(workflowProcess );
item.addRelationship(workflow);
item = item.apply();
I hope this helps.
Regards
newcomer
edit: You can find a programmers Guide here: www.aras.com/support/documentation/
There are a lot of examples you can lern from.
vasant - Friday, February 1, 2013 2:05 AM:
Hi,
Please find sample code here:
Dim status As String
Dim myi As Innovator = Me.getInnovator()
Dim e As Item
Dim currentItem As Item
AMLQuery += "<Item type='YOURITEMTYPE' action='get' select='YOURPROPERTIES'>"
AMLQuery += "<Relationships>"
AMLQuery += "<Item type='Workflow' action='get' select='related_id'>"
AMLQuery += "<related_id>"
AMLQuery += "<Item action='get' type='Workflow Process' select='id'>"
AMLQuery += "<Relationships>"
AMLQuery += "<Item action='get' type='Workflow Process Activity' select='related_id'>"
AMLQuery += "<related_id>"
AMLQuery += "<Item action='get' type='Activity' select='id' id='"+Me.getProperty("id")+"'></Item>"
AMLQuery += "</related_id>"
AMLQuery += "</Item>"
AMLQuery += "</Relationships>"
AMLQuery += "</Item>"
AMLQuery += "</related_id>"
AMLQuery += "</Item>"
AMLQuery += "</Relationships>"
AMLQuery += "</Item></AML>"
currentItem=myi.applyAML(AMLQuery)
status = currentItem.getProperty("state")
If status = "Submitted" And isnothing(currentItem.getProperty("snx_approvedby")) And currentItem.getProperty("snx_approvedby")="" Then
e = myi.newerror("<br><font color=red>You must enter an Approved Date for this Misc Credit Memo before you can complete this activity.")
Return e
End If
jbiggs - Friday, February 1, 2013 9:49 AM:
Thank you both for the help, I'll run through both sets of code when I have time and tease out how it works. I suppose AML must become my new favorite language :-)