vRealize Orchestrator (vRO) Resource Elements

Hi friends, in this article we will talk about resource elements. Resource element is a construct that allows us to use HTML, XML or TXT templates, and even images(PNG, JPG, JPEG, etc.) in a workflow.

Let’s login to vRO Client.

Select the Design view.

Create, Update and Manage Resource Element

Select Resource tab and create a new folder. I created the resource element folder.

Click on Workflow tab and create a new workflow. I chose “Create ResElem” as the workflow name.

After creating the workflow, click on the Schema tab. Drag and drop the Scriptable task item to the blue arrow in the schema.

I select Scriptable task and click on the Scripting tab.

Now let’s write a script that records the date and time in the resource element each time the workflow runs.

I used the following code to return the date and time.

var today = new Date();
var day = String(today.getDate());
var month = String(today.getMonth() + 1);
//Because January is 0 :)
var year = String(today.getFullYear());

var strToday = month + '/' + day + '/' + year;
// If you want, you can use the toLocaleDateString function for the date.
//Ex: var strToday = today.toLocaleDateString();

var strTime = today.toLocaleTimeString();

We can now save the data in the resource element. If the file was created before, it will be saved in it. If not, it will create the file.

var resElem = new MimeAttachment();
resElem.mimeType = "text/plain";
resElem.content = "Date : " + strToday + "\nTime : " + strTime;
//Template of resource element created.

var fileName = "today.txt";
var folder = "Resource Element";

var resElems = Server.getResourceElementCategoryWithPath(folder );
//Get all resource elements in "Resource Element" folder.

var control = true;
if (resElems.allResourceElements.length > 0){
	resElems.resourceElements.forEach(function(entry) { //loop  
		if(entry.name == fileName){ //get resource element by the name
			entry.setContentFromMimeAttachment(resElem); 
			//if file is found, update it.
			control = false;
		}
	});
}

if(control){ //if the file is not found, create it.
	Server.createResourceElement(folder, fileName, resElem);
}
//Resource element saved.

The first parameter of the createResourceElement function is the name of the folder on the Resource tab. The second parameter is the file that will be created in this folder. Finally, the third parameter is the data to be saved.

Click on the Save button and Run the workflow.

Workflow worked successfully. You can open the Resource tab and view the created file.

We’ve seen the date and time change when the workflow runs again.

You can find the workflow I used in my blog post on my GitHub page. If you would like to read another example I published about the resource element, you can visit this blog post.

Hopefully this post has been informative for you. If you have a question, opinion or request about the article, you can contact us from the comments below or my e-mail address. If you think this post is informative to others, be social and share it on social media! Thank you for reading !!

Leave a Reply

Your email address will not be published.