Create "Run Again" option for custom scripts #8046

Closed
opened 2025-12-29 20:31:40 +01:00 by adam · 4 comments
Owner

Originally created by @atownson on GitHub (May 12, 2023).

NetBox version

v3.4.8

Feature type

New functionality

Proposed functionality

I'm proposing to add functionality to custom scripts that would enable a script, once it's been run, to return to the script's input page and populate certain variable values with the values entered for that run (similar to how the "Create & Add Another" option works for the model create forms).

Here's how I would envision this working, feel free to adjust as needed:

  1. Configure which fields should have values populated with the run-again feature as a variable option in the script. Perhaps name the option store_value and it be a boolean type that defaults to False. Example: site = ObjectVar(label = 'Site', model = Site, store_value = True)
  2. Once the script is run, a JSON object is created representing the stored values for each variable configured (similar to the documented body payload for running the script via the API). Example: {"data": {"var1": "value1", "var2": "value2"}}
  3. If the JSON object has valid content, present a ?read-only? textbox to the user with the JSON content and a button to run the script again at the bottom of the script's results page (or on another tab or wherever else makes more sense).
  4. Clicking the "Run Again" button returns the user to the script's input page and populates the variable values based on the JSON object.

Use case

Adding a run-again option would speed up the process of running the same script multiple times with similar parameters. We have scripts that help users add devices and virtual machines with additional related objects such as contact assignments and primary and OOB IP addresses. Typically users add more than one device at a time.

Database changes

None

External dependencies

None

Originally created by @atownson on GitHub (May 12, 2023). ### NetBox version v3.4.8 ### Feature type New functionality ### Proposed functionality I'm proposing to add functionality to custom scripts that would enable a script, once it's been run, to return to the script's input page and populate certain variable values with the values entered for that run (similar to how the "Create & Add Another" option works for the model create forms). Here's how I would envision this working, feel free to adjust as needed: 1. Configure which fields should have values populated with the run-again feature as a variable option in the script. Perhaps name the option `store_value` and it be a boolean type that defaults to False. Example: `site = ObjectVar(label = 'Site', model = Site, store_value = True)` 2. Once the script is run, a JSON object is created representing the stored values for each variable configured (similar to the documented body payload for running the script via the API). Example: `{"data": {"var1": "value1", "var2": "value2"}}` 3. If the JSON object has valid content, present a ?read-only? textbox to the user with the JSON content and a button to run the script again at the bottom of the script's results page (or on another tab or wherever else makes more sense). 4. Clicking the "Run Again" button returns the user to the script's input page and populates the variable values based on the JSON object. ### Use case Adding a run-again option would speed up the process of running the same script multiple times with similar parameters. We have scripts that help users add devices and virtual machines with additional related objects such as contact assignments and primary and OOB IP addresses. Typically users add more than one device at a time. ### Database changes None ### External dependencies None
adam added the type: featurepending closurestatus: under review labels 2025-12-29 20:31:40 +01:00
adam closed this issue 2025-12-29 20:31:40 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 12, 2023):

There's definitely some overlap here with #9609 but this is probably a more detailed implementation. @atownson please have a look at that issue and let me know what you think.

@jeremystretch commented on GitHub (May 12, 2023): There's definitely some overlap here with #9609 but this is probably a more detailed implementation. @atownson please have a look at that issue and let me know what you think.
Author
Owner

@atownson commented on GitHub (May 12, 2023):

The dry-run option isn't something I've considered, and I'm not sure how @BarbarossaTM plans to implement. But perhaps it's as simple as script writers setting all variables with store_value to True. They would then just need to elect to commit the changes.

If that's not the desired user experience for #9609, then maybe two JSON payloads are created - one as detailed here and another representing all variables and their values. Then presenting the user with two options - one to completely re-run the script as it was just ran (but with a commit) and another to populate only the configured variables as detailed here. I'm not sure how to differentiate the button naming though. Maybe "Re-Run Script with Commit" and "Return To Script" respectively. Maybe also only present the "Re-Run Script with Commit" button only if commit was not checked on the script run.

Just my thoughts.

@atownson commented on GitHub (May 12, 2023): The dry-run option isn't something I've considered, and I'm not sure how @BarbarossaTM plans to implement. But perhaps it's as simple as script writers setting all variables with `store_value` to True. They would then just need to elect to commit the changes. If that's not the desired user experience for #9609, then maybe two JSON payloads are created - one as detailed here and another representing all variables and their values. Then presenting the user with two options - one to completely re-run the script as it was just ran (but with a commit) and another to populate only the configured variables as detailed here. I'm not sure how to differentiate the button naming though. Maybe "Re-Run Script with Commit" and "Return To Script" respectively. Maybe also only present the "Re-Run Script with Commit" button only if commit was not checked on the script run. Just my thoughts.
Author
Owner

@github-actions[bot] commented on GitHub (Aug 11, 2023):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Aug 11, 2023): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Sep 11, 2023):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Sep 11, 2023): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8046