Reusable Method


I am new to using Cloudforms and have been going over the Mastering Cloudforms Automation book. I have been able to create a few workflows succesfully since starting to look into it last month.

My question is a lot of my workflows are going to be “copy and paste” but only modifying a few fields, The method will connect to a Windows server using winrm and kick off a script.

The only thing that would change in the method are:
-Importing the inputs from the dialog
-The script with the arguments to kick off.

Is there a way to have a “Master Method” that can do this? This would also help because if i had multiple methods, i would have to set the username and password for each that is used to connect to the server using winrm


You could have multiple instances that all execute the same method. The differences would be set as variables of the class (i.e. what script to run). The method would reference the variables from the instance and the dialog to determine what script to run and arguments to pass. As long as the dialog element names are the same between the different dialogs the method would be able to reference them as well regardless of the instance.


You could create your “master method” to read inputs and the script name to be run from $evm.object, and then call the master method using various helper methods that handled the dialog input handling, etc.

These helper methods could call the master method using something like:


Your master method would receive these arguments using something like:

script_to_run = $evm.object['script']
arg1 = $evm.object['arg1']
arg2 = $evm.object['arg2']

Chapter 46 of the automation book describes argument passing between methods and instances, and case 3 in this chapter describes argument passing is this way when calling $evm.instantiate.

Hope this helps,


I think if we went this route I would have to store the username and password in each instance that we create.

The other main reason for seeing if we could have one main method is so if we have to update the username/password we have on our instance/methods, that we would only have to update it in one place and not for every instance/method.


Thanks for your guys replies (and your work on the Master Cloudforms Automation book).

I need to play around with this some more (I am still learning and trying to get other things figured out - like making a dynamic dropdown be able to be populated by a MSSQL query).

I definitely like the idea of it all being stored in the $evm.object and that ultimately being passed to the final method.

The only “gotcha” I can think of outside of actually getting in there and trying it is if cloudforms freaks out if there are different amount of arguments and how to account for that.

for instance, say i have the “Master Method” and it is alotting for 3 arguments. will things mess up if i run a script with only 2 arguments through it?


We tried this today and we were able to get this to successfully work.

I think it is really nice since if we have to change the way we call things in the “Master method” we only have to change it once and not every place we use it.

Thanks for your guys help on this.


Hi Peter,

Your automation book is excellent
I have one question here…
Calling another instance via instantiating is fine but when I instantiate that instance I would like to save the variable that the script passes on exit like a return value
Is there a way to save the return value ??




What we have done in a case like this is set $evm.object[‘result’] to the return data in the method which can be read by the caller.


Hi Eric,

Thanks for your response
Can you please give me an example of this as I instantiate to call another script
One parent script that calls child scripts and stores return value from the child scripts
Is there a way of doing inside the automation rather than using the API calls
I tried your $evm.object[‘result’] but that didnt work as well

temp1 script

res = $evm.object[‘result’]
$evm.log(“info”,“result is #{res}”)

temp2 script

def test()
t1 = “success”
$evm.log(“info”,“Called from temptest2”)
$evm.object[‘result’] = t1
return t1
t2 = test()
$evm.object[‘result’] = t2

Am i doing something wrong over here??




You want to save the returned object of the instantiate call and reference that. $evm.object is used as a reference to “the thing currently running” and not what you instantiated, hence the confusion.

sub_method = $evm.instantiate("/Example/Example-Integration/CloudformsInternal/temptest2")
if sub_method.nil?
  $evm.log("info", "something went wrong with the instantiation")
  $evm.log("info","result is #{sub_method['result']}")