Login to participate
Endpoint Management & Virtualization ArticlesRSS

Remove Domain from "Get Current User" Component

Steve Wayment's picture

This is the method I use to remove the Domain from the current user.  I generally use the HttpContext option of the "Get Current Windows User" component to retrieve the appropriate credentials.  This can sometimes be a little tricky, but there are other articles that can help you with this feature.

After retrieving the current Windows user in a live environment, you will generally get something similar to "Domain\User.Name".  I will always divide this string into two different variables, so I can use the Username for display and other processing options, and the Domain to determine routing, etc. 

The component I use to do this is called "Extract Text from Text" under the Text Handling tree.

Here is a basic example of the layout:
Workflow Overview
The "Get Current Windows User" component returns data in a "Current_User" variable.  This variable is then used for each Extract Text components you use.  Here is the "Return Username" configuration:
Return Username Config

The Current_User variable is passed into this component.  I have created a new variable called Username to pass the result to.  I also have a Domain variable for the second component.

At this point, if you have a constant length of domain names (i.e. all domains are configured as Domain1, Domain2, Domain3, etc.) you can put in a constant Begin Location.  It is important to note that the Begin Location should be the location AFTER the "\" in your domain, but the character locations start at 0, not 1.  If your Current_User variable returns ABC\Steve, your Begin location should start on the letter 'S', which is position 4.  However, it is best practice to account for all possibilities.  It is likely at some point that you will have a domain with a different length.  To account for this, we will use a Dynamic Model for the Begin Location.  Click the ellipsis button next to Begin Location, then select Dynamic Model and click Edit.

Begin Location Config

You will use the "Index of Text within Text" component to determine the location of your backslash, and the "Add Values" component to increase the returned value to the correct position.  (We want to strip our string beginning from the first letter after the backslash, so adding 1 to the returned position gives us the correct Begin Location.)
Dynamic Model Setup

Open your Index of Text component and set the following options:
Index of Text Config

I use the variable name "position" which I pass to the "Add" and "End" components of the module.

To retrieve the Domain, you would simply set your Begin Location to 0, uncheck the "Get All Text After Begin" checkbox, and use the same Dynamic Model for your Length.
Domain Config

You can now follow the same process to set up any subsequent components (or use the copy/paste feature). 

Hopefully this will provide you with a stable program, regardless of your organization.

Andy Tous's picture

You might also want to consider "Split Text Into Collection"

The component called "Split Text Into Collection" allows you to get the Username and Domain, both in a single step:

The below will show how to set the properties for the "Split Text Into Collection" and then show a debug run as an example. 
 

In this case my NT ID is: JardenCS\Andy and Get Current User generates a variable called v_CurrentUser.

  1. Insert Split Text Into Collection component after Get Current User and before the component where you will use the results on.
  2. Double-click to edit.

    imagebrowser image

  3. Insert variable generated by Get Current User in the Text To Split field.  In this case it is called: v_CurrentUser.
  4. Select Other as Delimiter.
  5. Enter \ in the Delimiter Text field.
  6. Enter the Output Variable Name.  In this case I used: a_DomainAndUser.
  7. You can leave everything set as default (for this case).

imagebrowser image

For this case, I used the Display Content component inside the dialog workflow so you can see the results.
imagebrowser image
This is how your Domain and User variables would look like when browsing and inserting them in other components.  Since the Domain is the first value before the \, it will display [first] right next to the variable name I selected (see a_DomainAndUser[first]) so, a_DomainAndUser[last] would be the Username:

imagebrowser image

When you debug your workflow, this is what you should get.

imagebrowser image

Hope this makes it easier when retrieving or separating your domain from user or vice versa.