VMware Cloud Community
caseybarela
Contributor
Contributor
Jump to solution

Unable to Set AD:User via String Input or Other method.

We are trying to use the Out of the Box AD "Change a user password" workflow. But we are getting stuck at the trying to pass the Variable of AD:User via anything else like changing it to STRING without any luck.

The workflow works fine when we run it via the play button in VCO, it forces you to navigate and find the user in the AD tree structure. We would like to be able to just enter in a SamAccount Name to be able to tell it the proper user without using the TREE Picker. This would allow us to pass the Variable via REST to VCO from ServiceNow in a STRING format.

Thanks in Advance if you can point me in the right direction or tell me what I'm doing wrong.

- Casey

1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi Casey,

What you need is a way to find an AD:User object given user's SAM account name.

Here is a sample code showing how this can be done:

// input: 'user' of type string

// result: 'aduser' of type AD:User

var found = ActiveDirectory.searchExactMatch("User", user, 1, AD_HostManager.findAllHosts()[0]); // returns an array of objects found

if (found == null || found.length == 0) {

  System.error("No matching user found");

} else {

  aduser = result[0];

  System.log("Found user: " + aduser.accountName + " , " + aduser.userPrincipalName);

}

The important piece above is line 4, where a search is initiated for an object of a given type (the first arg, 'User') having a specified name (the second arg, user), limiting the number of results (the third arg, 1) and searching over the first AD host (the fourth arg). You may customize the search arguments to fit your case.

So your custom workflow can have the 'user' as an input parameter of type string, the first item could be a scriptable task with the above code to find the corresponding AD:User object and storing it eg. as a workflow attribute, and the next item could be an invocation of the out-of-the-box workflow 'Change a user password' binding the computed AD:User attribute to the input parameter of the workflow.

View solution in original post

3 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi Casey,

What you need is a way to find an AD:User object given user's SAM account name.

Here is a sample code showing how this can be done:

// input: 'user' of type string

// result: 'aduser' of type AD:User

var found = ActiveDirectory.searchExactMatch("User", user, 1, AD_HostManager.findAllHosts()[0]); // returns an array of objects found

if (found == null || found.length == 0) {

  System.error("No matching user found");

} else {

  aduser = result[0];

  System.log("Found user: " + aduser.accountName + " , " + aduser.userPrincipalName);

}

The important piece above is line 4, where a search is initiated for an object of a given type (the first arg, 'User') having a specified name (the second arg, user), limiting the number of results (the third arg, 1) and searching over the first AD host (the fourth arg). You may customize the search arguments to fit your case.

So your custom workflow can have the 'user' as an input parameter of type string, the first item could be a scriptable task with the above code to find the corresponding AD:User object and storing it eg. as a workflow attribute, and the next item could be an invocation of the out-of-the-box workflow 'Change a user password' binding the computed AD:User attribute to the input parameter of the workflow.

jacksonecac
Enthusiast
Enthusiast
Jump to solution

^ Correct. You cannot specify things like strings when the parameter is expecting something like an object. Make sure you check the inputs of those workflows so you know what to provide.

A lot of vro scripting is taking inputs and returning the correct data types Smiley Happy

caseybarela
Contributor
Contributor
Jump to solution

Thanks for the help. Works like a dream.

Reply
0 Kudos