VMware Cloud Community
Beansley
Contributor
Contributor
Jump to solution

Pull logged in workflow username

seems like a simple task, but I'm having issues figuring it out.  I'd like to pull the username out as a string within a workflow to use within a field.  I can see the logic that's used to do the same sort of thing within the built in "Create Snapshot of resource pool VMs" workflow, but in that case it is appending the date:

var date = new Date();

snapName = snapNamePrefix + " " + date.toGMTString();

I attempted to search the API browser for username, came up with credential.username

Then attempted this:

var date = new Date();

var strUsername = new credential.username();

snapName = snapNamePrefix + " " + date.toGMTSTring() + " " + strUsername

So not sure how to approach this (I tried it w/out the new method in front as well).  While I've got your attention, is there something akin to an immediate pane, where I can see what a simple expression would return, or am I forced to save and close the workflow, then run it?

Thanks for looking!

Dave

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
tschoergez
Leadership
Leadership
Jump to solution

Hi!

Try to use

var currentUserName = Server.getCredential().username;

to figure out the currently logged in user.

If you want to get the user who started the Workflow, you can take it from the workflowToken:

var username = workflow.runningUserName;

See the original example on vcoteam.info:

http://www.vcoteam.info/learn-vco/code-snippets-cancel-one-of-your-running-workflows.html

and some background information about the WorkflowTokens:

http://www.vcoteam.info/learn-vco/how-to-retrieve-workflow-execution-details.html

http://www.vcoportal.de/2012/03/workflow-reflection/

Cheers,

Joerg

View solution in original post

0 Kudos
7 Replies
tschoergez
Leadership
Leadership
Jump to solution

Hi!

Try to use

var currentUserName = Server.getCredential().username;

to figure out the currently logged in user.

If you want to get the user who started the Workflow, you can take it from the workflowToken:

var username = workflow.runningUserName;

See the original example on vcoteam.info:

http://www.vcoteam.info/learn-vco/code-snippets-cancel-one-of-your-running-workflows.html

and some background information about the WorkflowTokens:

http://www.vcoteam.info/learn-vco/how-to-retrieve-workflow-execution-details.html

http://www.vcoportal.de/2012/03/workflow-reflection/

Cheers,

Joerg

0 Kudos
tschoergez
Leadership
Leadership
Jump to solution

Oh, and for your second question: there is no kind of "script debugger" in the vCO Client. So yes, you are forced to "Save and Close and Play" the workflow...:smileyplain:

0 Kudos
Beansley
Contributor
Contributor
Jump to solution

Thanks for the quick response!

Server.credential(). worked nicely, but

workflow.runningusername returned Undefined in my test.  Something I need to declare / define earlier in the workflow perhaps?

Better than error out, though Smiley Wink.  I've clearly got some learning to do.  Pretty nice how one can watch the logic flow in the workflow as it runs.

0 Kudos
tschoergez
Leadership
Leadership
Jump to solution

be aware: JavaScript is Case-Sensitive! the attribute of the workflowToken is named runningUserName....

Cheers, joerg

0 Kudos
FSvcoe
Enthusiast
Enthusiast
Jump to solution

"Oh, and for your second question: there is no kind of "script debugger" in the vCO Client. So yes, you are forced to "Save and Close and Play" the workflow...:smileyplain:"

Is this something we will see in the near term? It's the only IDE I've used that doesn't offer it...thanks.

0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

A debugger has been considered many times but always lower priority than everything new in the product.

This year is the same : expect significant upcoming end user experience improvements but no debugger yet.

Christophe.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
0 Kudos
FSvcoe
Enthusiast
Enthusiast
Jump to solution

Thanks Chris. Although I'm sure it would present a great deal of effort, I would strongly encourage the product folks to consider it. In an enterprise organization like ours it would be a huge benefit.

0 Kudos