I have been working on a method to auto create security tags and assign them to marked files on import, i found tidbits scattered in answers that helped me and thought i could put what i did to help others in the future.
Originally, this script sat as one unit and if it came across a security tag that already existed it would just throw an error and skip to the next step and assign to the groups which would likely throw an error if the tag did and then assign the tag to the file currently being worked. I kept running into errors when assigning the tag to the file and found that even though the tag was assigned to the account running the workflow that RASession would not pick up the changes until a new SDK session was started. So i had to separate the tag creation and group assignment into one script and the file tag assignment into a second script. Not sure if any one knows how to refresh RASession to pick up account changes?
protected override void Execute() { var tagName = GetTokenValue("ForEachEntry_CurrentEntry_SecurityTagName").ToString(); try{ var newTag = new TagInfo(); newTag.Name = tagName; newTag.Description = tagName; newTag.IsSecure = true; bool autoRenameTag = false; Tag.Create(newTag,autoRenameTag,RASession); } catch(Exception e) { //do nothing } try{ tagAGroup("workflow", tagName); tagAGroup("User Test Group", tagName); tagAGroup("Admin Test Group", tagName); } catch(Exception e) { //do nothing } tagAFile(int.Parse(GetTokenValue("ForEachEntry_CurrentEntry_ID").ToString()),tagName); } private void tagAGroup(string groupName, string tagName) { AccountReference tagGroup = new AccountReference(groupName, RASession); TrusteeInfo updateGroup = Trustee.GetInfo(tagGroup, RASession); updateGroup.AssignTag(Tag.GetInfo(tagName, RASession)); Trustee.SetInfo(tagGroup, updateGroup, RASession); updateGroup.Save(); } private void tagAFile(int docId, string tagName) { DocumentInfo doc = Document.GetDocumentInfo(docId, RASession); doc.AssignTag(Tag.GetInfo(tagName, RASession),""); }