cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
574
Views
0
Helpful
2
Replies

Velocity template

ErlingNygard
Level 1
Level 1

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?

1 Accepted Solution

Accepted Solutions

David Kuncik
Level 1
Level 1

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

View solution in original post

2 Replies 2

Preston Chilcote
Cisco Employee
Cisco Employee

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?

David Kuncik
Level 1
Level 1

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