VMware Cloud Community
GaneshShastri
Enthusiast
Enthusiast

Unable to validate ownerID_check - vRO

I have Javascript which runs for ownerID_check while creating new vm catalog. But all off sudden it stopped working, and throwing an error message.

"Action 'ownerID_check' in module 'org.company.<orgname>' failed : TypeError: Cannot read property "name" from undefined (org.company.<orgname>/ownerID_check#9)" 

There's no change in module, and also in script

JavaScript
var output =null;
if(Owner == null)
{
    output="Missing LAN ID"
}
if(Owner !== null){
    var users=Server.findAllForType("AD:User",Owner);

    //output = users[0].name;
    output=users[0].sAMAccountName

    System.log("name"+output)

}
if (output == null)
    {

        output="LAN ID does not exist" 
    }

 return output;
Reply
0 Kudos
1 Reply
StefanSchnell
Enthusiast
Enthusiast

Hello @GaneshShastri,

it seems that the owner being passed does not exist in AD, or maybe the AD is not available.

To get around this, the length of the users array can be queried:

 

var users = Server.findAllForType("AD:User", Owner);
if (users.length > 0) {
  var output = users[0].name;
} else {
  System.error("Owner does not exists");
}

 

Or you can use try-catch:

 

var users = Server.findAllForType("AD:User", Owner);
try {
  var output = users[0].name;
} catch (exception) {
  System.error("Owner does not exists");
}

 

Best regards
Stefan


More interesting information at blog.stschnell.de

Reply
0 Kudos