在 activity 的 on activate server event 建立對應的 server side method。該 method 的思路是從Activity Id 一路找到 ItemType 中目標簽核人員 (Identity) 的 property,再以此新增 Activity Assignment 到當前的 Activity。
/*
This method used for activity's on activate event.
*/
// Target itemtype, property
const string itemName = "Test ItemType";
const string propertyName = "pm_id";
// Target assignment parameters
const bool assignRequired = false;
const bool assignAllMember = true;
const int assignVoteWeight = 100;
Innovator inn = this.getInnovator();
string actId = this.getID();
string aidId = String.Empty;
// Get assign identity
Item itemType = inn.newItem(itemName, "get");
Item wflItem = itemType.createRelationship("Workflow", "get");
Item wpcItem = wflItem.createRelatedItem("Workflow Process", "get");
Item wpaItem = wpcItem.createRelationship("Workflow Process Activity", "get");
wpaItem.setProperty("related_id", actId);
itemType = itemType.apply();
aidId = itemType.getProperty(propertyName);
if(aidId == null) {
return inn.newError("Could not get assignment identity!");
}
// Create assignment to activity (need Aras PLM permission)
Aras.Server.Security.Identity plmIdentity = Aras.Server.Security.Identity.GetByName("Aras PLM");
bool permissionWasSet = Aras.Server.Security.Permission.GrantIdentity(plmIdentity);
try {
// Make sure assigned identity is not exist in activity
Item assItem = inn.newItem("Activity Assignment", "get");
assItem.setProperty("source_id", actId);
assItem.setProperty("related_id", aidId);
bool noExistIdentity = assItem.apply().getItemCount() == 0;
if(noExistIdentity) {
// Add
assItem.setAction("add");
assItem.setProperty("is_required", assignRequired ? "1" : "0");
assItem.setProperty("for_all_members", assignAllMember? "1" : "0");
assItem.setProperty("voting_weight", assignVoteWeight.ToString());
assItem.apply();
}
}
finally {
if (permissionWasSet) {
Aras.Server.Security.Permissions.RevokeIdentity(plmIdentity);
}
}
return this;

Leave a comment