Chapter 46. Argument Passing and Handling
Over the preceding chapters we have discovered several ways of calling Automate instances. In some cases we need to pass arguments into the instance’s method, but the way that we pass arguments into methods, and receive them from inside the method, varies depending on how the instance is called. We need to consider this if we’re writing code that can be called in several ways, such as from a button and/or from an API call.
In this chapter we’ll look at how we pass arguments into instances and how we retrieve them from inside the method. We will call the same instance (ObjectWalker) four ways, passing two arguments each time: lunch
and dinner
. We can use object_walker_reader to show us where the arguments can be read from inside our called method.
Case 1: Calling from a Button
For this first case we call ObjectWalker (via /System/Process/Request/Call_Instance) from a button. We create a button dialog that prompts for two text box fields (see Figure 46-1).
We then add the button to a button group anywhere.
If we click on the button and enter the values salad
and pasta
into the dialog boxes, we see the dialog values appear in $evm.root
in the receiving method, indexed by the key name prefixed by dialog_
:
~/object_walker_reader.rb | grep -P "lunch|dinner" | $evm.root['dialog_dinner'] ...
Get Mastering CloudForms Automation now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.