VMware Cloud Community
dxb74
Contributor
Contributor

vRA8 - Convert username to last name, first name format

I am trying to use an HTTP-REST call to open a ticket in our ticketing system from vRA for a user requesting a server build.  I can get the name of the requestor with the '__metadata_userName' parameter, but I need it to be in Last Name, First Name format to feed into the ticketing system.

We have an integration set up to Active Directory but I'm an ops guy and don't know how to write the code that will do a lookup in AD by username and return the corresponding Last Name, First Name for the account.  ???

0 Kudos
2 Replies
rwk1982
Enthusiast
Enthusiast

Hello!

You can get the Information from vRA with an API Request. Get the Values from "__metadata_userName" and "__metadata_orgId" and make a GET Request to "/csp/gateway/am/api/users/" + userName + "/orgs/" + orgId + "/info". For Testing:

var val2return = new Properties
var vra_usr = executionContext.getParameter("__metadata_userName")
var vra_orgid = executionContext.getParameter("__metadata_orgId")
var vra_uri = "/csp/gateway/am/api/users/" + vra_usr + "/orgs/" + vra_orgid + "/info"

var vra_user = "yourUsername"
var vra_pass = "yourPassword"
var vra_url = "https://vra.fq.dn"

var vra_host = VraHostManager.createHost({
    name: "dummy",
    vraHost: vra_url,
    user: vra_user,
    password: vra_pass,
    connectionType: "vra-onprem",
    sessionMode: "Shared Session"
})


var vra_rest = vra_host.createRestClient()
var vra_request = vra_rest.createRequest("GET", vra_uri, null);

var vra_response = vra_rest.execute(vra_request)

val2return = JSON.parse(vra_response.contentAsString)

var firstName = val2return.user.firstName
var lastName = val2return.user.lastName
var email = val2return.user.email

System.log(firstName + " " + lastName + " (" + email + ")")

vra_host.destroy()

return val2return

 

Drink coffee.. Do stupid things faster with more energy...
Tags (1)
xian_
Expert
Expert

I prefer to create the vRA host in vRO once and pass it as a parameter to the workflows doing API calls.

Other than that I like the code shared.