Default value for Variable Reference in Scripts #17989
-
Hello, I am working on a script to create VLAN Groups, VLANs, Prefixes. I would like to be able to use a default value for the VLAN Prefix. data_prefix = IPNetworkVar(
label="Prefix Vlan Data",
description="Type de prefix pour Vlan Data",
default="192.168.101.0/24",
required=False,
) As I see in Netbox documentation : https://netbox.readthedocs.io/en/stable/customization/custom-scripts/#default-options: However it never works... I can't get the default value. Even if the field would be a StringVar... test=StringVar(
default="testttt",
required=False,
) and tested calling this : result :
expected result :
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Netbox version? This script works for me under Netbox 4.1.6:
Result: and after correcting the (invalid) prefix so that the script can run: |
Beta Was this translation helpful? Give feedback.
-
Hi, i’m running Netbox 4.1.4
…On Tue 12 Nov 2024 at 18:15, Brian Candler ***@***.***> wrote:
Netbox version?
This script works for me under Netbox 4.1.6:
from extras.scripts import Script, IPNetworkVar
class ShowPrefix(Script):
class Meta:
name = "Show Prefix"
commit_default = False
prefix = IPNetworkVar(
description="Prefix",
required=False,
default="1.2.3.4/24",
)
def run(self, data, commit):
return "prefix: %s" % repr(data["prefix"])
Result:
image.png (view on web)
<https://github.com/user-attachments/assets/89f408c6-0a32-42c3-bc61-8fc4fe0ef3e2>
—
Reply to this email directly, view it on GitHub
<#17989 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A2DITZCKYNHP7PP7CLE6NHL2AIZR5AVCNFSM6AAAAABRUKN4N6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCMRSHE3DEMI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
Yes. But it depends what you mean by "ran your script".
I ran it by going to Customizations > Scripts, clicking on the script name in the left-hand column:
This gives the data entry form, then I clicked Run Script at the bottom of the form.
Maybe you clicked the "Run Script" button on the right (or "Run Again" as it shows now); if so, it doesn't prompt for anything.
If you were to say that's confusing and/or not useful, I wouldn't argue. Perhaps it should only be shown for scripts that don't declare any parameters.