VMware Cloud Community
BillStreet00
Enthusiast
Enthusiast
Jump to solution

vRO 8 - Notifications

I have a requirement to send out notification such as server build complete, owner change, lease change etc..  I currently have a WF that takes in a string of data, creates the email and then sends it.  Within that string of data I have a variable that leads into a case statement telling me which body to use.  The WF works and works well but if I have to add a new notification I have to update the WF which starts a long change process.  

Rather than a variable which then is read through the case statement to select which decides which scriptable task to run I'd like to pull in some kind of template stored elsewhere in vRO.  For example a template called newServer, changeLease or changeOwner. Because the template itself would be kept outside the WF I would be able to add them on the fly.  I was originally thinking of creating the templates as a Resource Item but that doesn't seem to do what I need.

Any advice? 

Reply
0 Kudos
1 Solution

Accepted Solutions
xian_
Expert
Expert
Jump to solution

Not sure what you want to achieve but you can iterate over the args and within an arg with the following code:

for each(var row in inString.args) {
	for (var key in row) {
		System.log(key + ": " + row[key])
	}
}

View solution in original post

Reply
0 Kudos
6 Replies
xian_
Expert
Expert
Jump to solution

I recommend Resource Elements. You can load by name / path and that allows to make your decision logic easier (even choosing dynamically).

Also, you can make the text in the Resource Element behave like a template: just define some syntax (ie. {{ variable }} ) that you replace with Javascript before sending out.

BillStreet00
Enthusiast
Enthusiast
Jump to solution

Thanks!  That's the way I was leaning.  The problem I was having was reading the JSON string.

Exmaple: var inString = {"template":"serverBuild.txt","toAddress":"my.email@myemail.org","subject":"Server Build Complete","args":[{"serverName": "STREET001.some.org","createDate":"06/06/2021"}]};

I need to be able to recurse args because each template would have its own variables with some having more and some less variables by using

results = inString['args'];
if (results.length > 0){
   var col1 = results[0];
   for(var key in col1){
      keyObj = '(('+key+'}}';
      System.log(keyObj);
      tmp1.push(keyObj);

I can fish out the field name but the field value seems to be my issue.  I should be able to address my server name as inString.serverName but I keep getting 'undefined' or 'objectObject'.

Do you have any suggestions?

Reply
0 Kudos
xian_
Expert
Expert
Jump to solution

inString.args[0].serverName should give you the server name.

Reply
0 Kudos
BillStreet00
Enthusiast
Enthusiast
Jump to solution

That does work but I need to recurse args so I would need something like inString.args[0].'variableName'.

Reply
0 Kudos
xian_
Expert
Expert
Jump to solution

Not sure what you want to achieve but you can iterate over the args and within an arg with the following code:

for each(var row in inString.args) {
	for (var key in row) {
		System.log(key + ": " + row[key])
	}
}
Reply
0 Kudos
BillStreet00
Enthusiast
Enthusiast
Jump to solution

Perfect.  This has helped my understanding a lot.  Thanks again.

Reply
0 Kudos