Rename Accounts on User Status Change Using Workflows
The following workflow sample outlines how to update a username via a workflow.
Configuration
Create an “Action” which has the following data:
Name: Update Account Name
Script: (see below)User user = User.GetByID(Convert.ToInt32(context["UserID"])); //This Workflow is being triggered by User.Update Event. So the UserID is in the Context UserStatusType st = user.GetUserStatusType(); //Fetch the current Status Type from the user User oldUser = User.Deserialize((string)context["OldRow"]); //Get the old Username (In case it has changed) UserStatusType oldst = oldUser.GetUserStatusType(); //Get the old Status Type (Incase it changed) Owner owner = user.GetActingOwner(); //Get the users Owner // Logisense.Boss.Logic.Core.Alert.Create(user.Name + " here1 ", user.ActingOwnerID); String name = user.Name; //Create a String Variable the contains the Users Account Name if (name.Contains("R" + DateTime.Now.Year + "/" + DateTime.Now.Month)) //Check to see if the Name has already been changed (Exit the script if it has) Prevents Loop. { return true; } else if (oldst.Name != "Disabled" && st.Name == "Disabled") //Check to see if the status was changed from anything else to Disabled (Also protects against Loop) { User oldName = user; foreach (Logisense.Boss.Logic.Core.UserTree ut in Logisense.Boss.Logic.Core. User.GetUserTree(user.ID)) //Checks to see if there are any sub accounts under this user. { //Logisense.Boss.Logic.Core.Alert.Create(ut.Name, user.ActingOwnerID); User subaccount = User.GetByID(ut.UserID); //Gets the UserID for each of the subaccounts subaccount.Name = ut.Name + "R" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day; //Sets the new name on the Subaccount subaccount.UserStatusTypeID = st.ID; //Sets the Disable type the same as the Parent account subaccount.Update(); //Updates the account with the above } // Logisense.Boss.Logic.Core.Alert.Create(user.Name + " here2 ", user.ActingOwnerID); user.Name = oldName.Name + "R" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day; //This section effects the account that was originally changed setting a New Name on the account user.Update(); //Updates the account with the above name change } return true;
Create a “Workflow Event” with the following data:
Name: Update Account Name
Event Code: User.Update
Script: noneCreate a workflow with the above action