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

Question

Question

Script Task Not Recognizing Tokens

asked on March 18, 2020 Show version history

We are working on a script task to add and remove members from a group.  The task only works if the values are hard coded within the task.

Here is the code that works:

            //Create a variable for the group
            string GroupName = "Test";

            //Identify a Win Account to Remove
            string WinName = "ABC\\NewUser";

            // Lookup the account by name to get the SID
            AccountReference ActRef = new AccountReference(WinName, RASession);

            // Retrieve the SID
            SecurityIdentifier sid = actRef.ToSecurityIdentifier();
 
            //Get the Group 
            GroupInfo gi = (GroupInfo)Account.GetInfo(GroupName, RASession);

            //Remove the specific Windows Account
            gi.UnlinkWindowsAccount(sid);
 
            // Save the GroupInfo object
            gi.Save();

This all works.  The problem arises when we try to use any token in place of the hard coded value.  

For instance, none of these work, giving us a Trustee Not Found message:

 

            //Using properties from the FindGroup Task
            string GroupName = "FindGroup_Display Name";

            //Using properties from the FindGroup Task
            string GroupName = "FindGroup_Account Name";

            //Using properties from the FindGroup Task
            string GroupName = "FindGroup_Qualified Name";

	    //Using a hard coded token name, defined in Assign Token Values
            //and hard coded to "Test"	
            string GroupName = "GroupName";

All of these tokens show up in the Track Tokens list with the correct name, "Test".  Is there something obvious we are missing?

0 0

Answer

SELECTED ANSWER
replied on March 18, 2020 Show version history

You are not getting the token properly.  You are just setting your value to the token name.  Instead use the GetTokenValue() function.

String sTokenValue = GetTokenValue("TokenName");

 

1 0
replied on March 18, 2020

Of course - rookie mistake!  Thanks Bert.

0 0
replied on April 30, 2020

This particular saga had an additional chapter.  I was invoking the rule from another rule.  The Input parameters are passed in to the rule as an array in all cases.  You have to normalize the Input parameter by using an Assign Token Value task, assigning the value of the Input parameter to itself.  Then you can address the value in a script task.  See:  https://answers.laserfiche.com/questions/108674/Timing-and-Behavior-of-Input-and-Output-Parameters

0 0

Replies

replied on August 25, 2021

When I try to use this script I get the error:

  • The type or namespace name 'SecurityIdentifier' could not be found (are you missing a using directive or an assembly reference?)

What assembly did you reference so you could use "SecurityIdentifier"?  

0 0
replied on August 25, 2021
3 0
replied on August 27, 2021

You are awesome!  Thanks a bunch as this has saved me a ton of time adding AD groups.

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

Sign in to reply to this post.