Get REST Operations on basis of [method urlTemplate] in vRO

Sometimes, we want to get a specific entity in our scripts in vRO workflows or actions. The best way would be to use Server.findAllForType(ObjectType, query) and just pass some kind of id in this query and you are good to go.

However, in some cases when id is not unique or sufficient to make it useful, lets say in a multi-environment where you promote the code through different environments but the IDs of these entities doesn’t remain same. In that case, code will fail.

Therefore, I have created this script to get the REST Operation on the basis of method & urlTemplate attributes. I tried finding the REST operation using findAllForType on the basis on name attribute but it didn’t work. What really worked was urlTemplate attribute. But urlTemplate wont be enough alone as any URL can have multiple methods like GET /url/entity or POST /url/entity etc. However, method and URL combination would be unique per REST Host each and every time.

var RestOp = "POST /auth/token"; //make this as string input
var method = RestOp.split(" ")[0];
var URL = RestOp.split(" ")[1];
var searchedOps = Server.findAllForType("REST:RESTOperation", URL);
for each(i in searchedOps){
    if(i.method == method){
        return i; //typeof REST:RESTOperation
    }
}

Remember that this script will show duplicate entries if multiple instance of same tools are added in vRO Inventory. In that case, create a way to find a particular REST:RESTHost would be required. It can be done via

  • Setting and getting custom properties Server.setCustomProperty(); and create action to get the desired host.
  • Using Server.findAllForType(“REST:RESTHost”) method and name (set it unique while adding REST Host).
  • Using Transient REST Host.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s