Change Field Set to Workflow Activity
- 3 years ago
I guess I should have come back to this and post the C# method I use. I have this assigned to the Activities of the Workflow Template with an On Activate event.
[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:9cde3055-6429-4da1-990b-055ed4c4c546:type=text&text=%2F%2F%20Called%20OnActivate%20from%20activities%20in%20a%20change%20workflow.%20%20Gets%20the%20Activity%20name%20and%20assigns%20it%20to%20the%20sm_workflow_activity%20field%0A%2F%2F%20Works%20as%20of%2030%20June%202023%20%20NDH%0A%0AInnovator%20inn%20%3D%20this.getInnovator%28%29%3B%0Astring%20actId%20%3D%20this.getID%28%29%3B%20%20%2F%2F%20GET%20current%20Activity%20ID%0A%0A%2F%2F%20Added%20for%20Method%20identification%20associated%20to%20error%20message%20%2027%20September%202022%20%20NDH%0Astring%20methodName%20%3D%20%22%5Cr%5Cn%20Method%3A%20%20sm_Get_Activity_Name%22%3B%0A%0A%2F%2F%20GET%20workflow%20item%0AItem%20wflItem%20%3D%20this.newItem%28%22Workflow%22%2C%22get%22%29%3B%0A%20%20%20%20wflItem.setAttribute%28%22select%22%2C%22source_id%2Csource_type%22%29%3B%0A%20%20%20%20%0AItem%20wflProc%20%3D%20wflItem.createRelatedItem%28%22Workflow%20Process%22%2C%22get%22%29%3B%0A%20%20%20%20wflProc.setAttribute%28%22select%22%2C%22name%22%29%3B%0A%0AItem%20wflProcAct%20%3D%20wflProc.createRelationship%28%22Workflow%20Process%20Activity%22%2C%22get%22%29%3B%0A%20%20%20%20wflProcAct.setAttribute%28%22select%22%2C%22related_id%2Cname%22%29%3B%0A%20%20%20%20wflProcAct.setProperty%28%22related_id%22%2Cthis.getID%28%29%29%3B%0A%20%20%20%20wflItem%20%3D%20wflItem.apply%28%29%3B%0A%0A%2F%2F%20VERIFY%20that%20the%20Workflow%20has%20been%20retrieved%0Aif%20%28wflItem.getItemCount%28%29%20%21%3D%201%20%7C%7C%20wflItem.getProperty%28%22source_id%22%2C%22%22%29.Length%20%21%3D%2032%20%7C%7C%20wflItem.getPropertyAttribute%28%22source_type%22%2C%22keyed_name%22%2C%22%22%29.Length%20%3C%201%29%0A%7B%0A%20%20%20%20return%20inn.newError%28%22Error%20retrieving%20workflow%3A%20%22%20%2B%20wflItem.getErrorDetail%28%29%20%2B%20methodName%29%3B%0A%7D%0A%0A%2F%2F%20GET%20ItemType%20of%20the%20change%20using%20the%20Method%20-%20labs_GetControlledItemCSharp%0AItem%20controlledItem%20%3D%20this.newItem%28this.getAttribute%28%22type%22%29%2C%20%22labs_GetControlledItemCSharp%22%29%3B%20%0A%20%20%20%20controlledItem.setID%28this.getID%28%29%29%3B%20%0A%20%20%20%20controlledItem%20%3D%20controlledItem.apply%28%29%3B%0A%0AItem%20wflActivity%20%3D%20this.newItem%28%22Activity%22%2C%22get%22%29%3B%0A%20%20%20%20wflActivity.setAttribute%28%22select%22%2C%22name%22%29%3B%0A%20%20%20%20wflActivity.setID%28wflProcAct.getProperty%28%22related_id%22%29%29%3B%0A%20%20%20%20wflActivity%20%3D%20wflActivity.apply%28%29%3B%0A%0Astring%20cmType%20%3D%20controlledItem.getAttribute%28%22type%22%29%3B%0Astring%20activityName%20%3D%20%22%22%3B%0A%0Aswitch%28wflActivity.getProperty%28%22name%22%29%29%0A%7B%0A%20%20%20%20case%20%22Close%20Change%22%3A%0A%20%20%20%20case%20%22Close%20ECR%22%3A%0A%20%20%20%20case%20%22End%22%3A%0A%20%20%20%20%20%20%20%20activityName%3D%22Closed%20-%20Completed%22%3B%0A%20%20%20%20%20%20%20%20break%3B%0A%20%20%20%20%0A%20%20%20%20case%20%22Cancel%20Change%22%3A%0A%20%20%20%20case%20%22Cancelled%22%3A%0A%20%20%20%20%20%20%20%20activityName%3D%22Closed%20-%20Cancelled%22%3B%0A%20%20%20%20%20%20%20%20break%3B%0A%20%20%20%20%0A%20%20%20%20default%3A%0A%20%20%20%20%20%20%20%20activityName%3DwflActivity.getProperty%28%22name%22%29%3B%0A%20%20%20%20%20%20%20%20break%3B%0A%7D%0A%0Abool%20permissionWasSet%20%3D%20false%3B%0AAras.Server.Security.Identity%20transIdentity%20%3D%20Aras.Server.Security.Identity.GetByName%28%22Aras%20PLM%22%29%3B%0A%0Atry%0A%7B%0A%20%20%20%20%2F%2F%20permissionWasSet%20%3D%20Aras.Server.Security.Permissions.GrantIdentity%28transIdentity%29%3B%0A%20%20%20%20Aras.Server.Security.Identity%20admin%20%3D%20null%3B%0A%09bool%20permsWasSet%20%3D%20false%3B%0A%09%0A%09admin%20%3D%20Aras.Server.Security.Identity.GetByName%28%22Aras%20PLM%22%29%3B%0A%09permsWasSet%20%3D%20Aras.Server.Security.Permissions.GrantIdentity%28admin%29%3B%0A%20%20%20%20%0A%20%20%20%20%2F%2F%20SET%20the%20Workflow%20Activity%20field%20from%20the%20change%0A%20%20%20%20var%20ecoParent%20%3D%20this.newItem%28cmType%2C%20%22edit%22%29%3B%0A%20%20%20%20%20%20%20%20ecoParent.setID%28wflItem.getProperty%28%22source_id%22%29%29%3B%0A%20%20%20%20%20%20%20%20ecoParent.setProperty%28%22sm_workflow_activity%22%2CactivityName%29%3B%0A%20%20%20%20%20%20%20%20ecoParent%20%3D%20ecoParent.apply%28%29%3B%0A%7D%0A%0Afinally%0A%7B%0A%20%20%20%20if%20%28permissionWasSet%29%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20Aras.Server.Security.Permissions.RevokeIdentity%28transIdentity%29%3B%0A%20%20%20%20%7D%0A%7D%0A%0Areturn%20this%3B%0A%0A%20%20%20%20%2F%2F%20return%20inn.newError%28%22Test%3A%20%22%20%2B%20activityName%29%3B]