You are viewing limited content. For full access, please sign in.

Discussion

Discussion

Workflow SDK: Create Security Tag and Assign

posted on October 26, 2020

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),"");

        }

 

0 0
replied on October 26, 2020 Show version history

Based on what the documentation is telling me ...

You could use Tag.EnumAll to check for the tag's existence, and if it's present use that instance to tag the group, instead of relying on the error.  Then, if you have to create it, instead of treating Tag.Create() as a void method, use the TagInfo object returned from Tag.Create() to set the group's tag.  

 

var newTag = new TagInfo(); doesn't represent the TagInfo that's actually in the repository - it's just a local object.

Tag.Create() creates a new TagInfo object that represents a tag in the repository.

I'd also pass a TagInfo object to tagAGroup() instead of a string of the tab name.

 

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.