Forum Discussion
Hi rif6894,
If you copy the following into your onActivate method, it should do what you need (tested for Innovator 12.0, older versions might not support all of the C# functionality in the code). Note my "ECR coordinator" property on the ECR has name "ecr_coordinator" and the ID of my "ECR coordinator" identity is '1999BBE8AC784D1C8E99A74FC6C9E537
'.
EcrCoordinatorHandler ecrHandler = new EcrCoordinatorHandler(this);
return ecrHandler.OnActivate();
}
}
public class EcrCoordinatorHandler
{
private readonly Innovator _innovator;
private readonly Item _thisItem;
public EcrCoordinatorHandler(Item item)
{
_thisItem = item;
_innovator = item.getInnovator();
}
public Item OnActivate()
{
Item ecrInstance = GetEcrInstance();
string ecrCoordinatorId = ecrInstance.getProperty("ecr_coordinator");
return string.IsNullOrWhiteSpace(ecrCoordinatorId)
? _innovator.newError("No ecr_coordinator found.")
: SetEcrCoordinatorAssignments(ecrCoordinatorId);
}
private Item SetEcrCoordinatorAssignments(string ecrCoordinatorId)
{
Item activityAssignment = _innovator.newItem("Activity Assignment", "edit");
string whereClause =
$"innovator.[Activity_Assignment].source_id='{_thisItem.getID()}' AND innovator.[Activity_Assignment].related_id='1999BBE8AC784D1C8E99A74FC6C9E537'";
activityAssignment.setAttribute("where", whereClause);
activityAssignment.setProperty("related_id", ecrCoordinatorId);
return activityAssignment.apply();
}
private Item GetEcrInstance()
{
Item workflow = _innovator.newItem("Workflow", "get");
workflow.setAttribute("select", "source_type, source_id");
Item workflowProcess = _innovator.newItem("Workflow Process", "get");
Item workflowProcessActivity = _innovator.newItem("Workflow Process Activity", "get");
workflowProcessActivity.setProperty("related_id", _thisItem.getID());
workflowProcess.addRelationship(workflowProcessActivity);
workflow.setRelatedItem(workflowProcess);
workflow = workflow.apply();
Item controlledItem = _innovator.newItem();
controlledItem.setAction("get");
controlledItem.setAttribute("typeId", workflow.getProperty("source_type"));
controlledItem.setID(workflow.getProperty("source_id"));
return controlledItem.apply();
Tested it for a setup similar to yours and it worked as intended. No idea if this is all kosher, but since no one else has answered in three days, I thought I might as well.
The code is in such a shape because I simply adapted something I already had in my own "ArasHelpersAndHandlers" library (I had a use case similar to yours and only had to change a bit of the code). You can, of course, change that on your end so that you only have the method, without any class or anything like that.
Cheers,
C
C
Thanks for your response.
I have re-written in VIsual Basic, using your schema and approach.
Works okay, so thank you for your assistance.
Regards
RiF