VMware Aria

 View Only

 Stand Alone vRO - Get "Started By"

KevB's profile image
KevB posted Sep 25, 2024 12:37 PM

So.....

     I have started at a new employer and they do not have the full Aria Automation suite. Most of you may know if you don't have full on vRA or Assembler, Orchestrator comes with vCenter and is licensed with vCenter. I have experience with the Aria Automation suite but not stand alone Orchestrator. Orchestrator is installed and working great. I am building workflows etc like one would normally but I'm finding it a challenge to get metadata. Usually you would have metadata that would provide a userName from the person making the request in vRA. When it's a stand alone orchestrator you don't have the same inputProperties / metadata. I see under the General tab of a workflow that has been run is a "Started by" value which I'd like to get. Is anyone aware of how to get that or is it simply not possible? I tried.....

System.getContext();
Logged that out to - ch.dunes.scripting.jsmodel.ExecutionContextObject@3562770
Not all that helpful :). If anyone has some advice I would appreciate it. I will attach a picture of what I mean and you can see it on your workflows that you have ran under the General tab next to Variables.
I really don't want to ask the user for their username / email address but I may have to in the end.
TIA
Sravan_k's profile image
Sravan_k

In standalone Orchestrator, you don't have the same metadata access as you would in vRA, but you can still retrieve certain information. The "Started by" value you see under the General tab can be accessed by using the system's context, which tracks the user who initiated the workflow.

Sravan_k's profile image
Sravan_k

or add a scriptable task in to workflow as element and add these below lines

var currentUser = System.getCurrentUser();
var userName = currentUser.getName();
System.log("Workflow started by: " + userName); 

KevB's profile image
KevB

Thank you @Sravan_k I really appreciate your help. I'll give this a go and mark it an the answer as soon as I can test.

KevB's profile image
KevB

So I gave this a try and this is the error I received. I tried to log out ch.dunes.scripting.jsmodel.ExecutionContextObject when logging out System.getContext(); but I couldn't get any values. Perhaps if I could log that out I could see what values I could get? Here is the output from the scriptable task you provided as an example.

2024-12-17 08:19:06.593 -07:00debug__item_stack:/item1
2024-12-17 08:19:06.597 -07:00errorError in (Workflow:test context value / Scriptable task (item1)#12759) TypeError: Cannot find default value for object.
2024-12-17 08:19:06.606 -07:00errorWorkflow execution stack:
***
item: 'test context value/item1', state: 'failed', business state: 'null', exception: 'TypeError: Cannot find default value for object. (Workflow:test context value / Scriptable task (item1)#12759)'
workflow: 'test context value' (3c8a81e6-6455-4a80-bca9-4a35a83aa0ca) 
|  'no inputs'
|  'no outputs'
|  'no attributes'
*** End of execution stack.

Sravan_k's profile image
Sravan_k

You are welcome..

The error TypeError: Cannot find default value for object suggests that the System.getCurrentUser() call is returning null or an object that doesn’t have the expected methods/properties. This often happens in standalone Orchestrator if the workflow is not triggered by an authenticated user session (e.g., triggered programmatically or by a scheduled task).

can you update the old code with below for debugging?

try {
    var currentUser = System.getCurrentUser();
    if (currentUser) {
        var userName = currentUser.getName();
        System.log("Workflow started by: " + userName);
    } else {
        System.warn("System.getCurrentUser() returned null. Workflow not triggered by a user?");
    }
} catch (e) {
    System.error("An error occurred while retrieving the current user: " + e);
}
 

KevB's profile image
KevB

Thanks for getting back so quickly. This is what I see and I am the one executing this test workflow. It's a very simple one that only has the code you provided to keep it simple. This is the out...

2024-12-17 08:48:17.466 -07:00debug__item_stack:/item1
2024-12-17 08:48:17.471 -07:00errorAn error occurred while retrieving the current user: TypeError: Cannot find default value for object.
2024-12-17 08:48:17.474 -07:00debug__item_stack:/item0