03-20-2023 04:00 AM
Hi
I'm trying to set a variable after a if statement but it doesn't recognize it as a set variable.
My code is like this:
#if( $__device.hostname == "switch01" )
#set( $permitip = '1.2.3.4' )
#end
When I run a simulation i have to fill in the $permitip variable, it won't detect it as already filled in.
Does anyone know how to do this?
Solved! Go to Solution.
04-21-2023 04:30 AM
Hi,
It asks for the permitip because it needs a lets say default value if the conditional fails
so it needs to look like this:
#set( $permitip = "4.3.2.1" )
#if( $__device.hostname == "switch01" )
#set( $permitip = "1.2.3.4" )
#end
this way DNA does not ask for the variable to be filled beforehad
if you dont hit the if statement you have a default value, otherwise it should work as intended
03-20-2023 08:59 AM
You can review VTL documentation for this too since it's not a Cisco specific thing. I don't think VTL has a concept of local scope, so #set statements are probably expected to be outside of if/else (at least for the initial definition). Can you get by with swapping your first two lines?
04-21-2023 04:30 AM
Hi,
It asks for the permitip because it needs a lets say default value if the conditional fails
so it needs to look like this:
#set( $permitip = "4.3.2.1" )
#if( $__device.hostname == "switch01" )
#set( $permitip = "1.2.3.4" )
#end
this way DNA does not ask for the variable to be filled beforehad
if you dont hit the if statement you have a default value, otherwise it should work as intended
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide