• Blog posts

    Bio

    By Luke Davenport 

    This is one for the more advanced iLogic users….

    Question: If I need to use a variable in many different places in an iLogic rule, and my iLogic rule has subroutines within it (rather than a single ‘top to bottom’ routine), can I make a variable ‘global’ so that it is accessible in all of the sub-routines without having to send it explicitly to each one?

    (If the above sentence sounds like Klingon to you, then have a look at some of our other iLogic blogs to get up to speed!)

    Well the answer is yes, you can use global variables, and this was pleasant news to me!

    Here’s how:

    • Type: ‘Class ThisRule’ at the start of the rule
    • Declare any global variables you need – something like this:

    Dim NewWebsiteName As String = “www.cadlinecommunity.co.uk” 

    • Type: ‘Sub Main’
    • Write all your code
    • Type ‘End Sub’ at the end of the sub
    • Include any subroutines here….
    • Type ‘End Class’ at the end of the rule

    Simple? Here’s an image of an iLogic rule that includes a global variable called ‘NewWebsiteName’. It contains a sub-routine that creates a custom iProperty called ‘URL’ in each component in the assembly, using the global variable. This is much easier than sending variables to the subroutine explicitly, especially for more complex iLogic rules.

    Hope this helps someone out there!