You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be great if Groovy Console could provide a dry-run method. So some second button to run the script without saving any changes.
This could be done by using a wrapper around the used ResourceResolver and its session object. This could then ignore calls to resolver.commit() and session.save().
On the other hand, for non-dry-runs the session.save() could be called directly by Groovy Console. This way there is no more need for session.save() at the end of all scripts.
Bindings also need to know about the dry-run. So the information needs to be provided to them, too.
The text was updated successfully, but these errors were encountered:
A pattern I often used was creating a SAVE field at the top of the script you can use @Field to make this available everywhere in the script.
Once I had a version with the data section, I added some JSON, that included that flag, and read it (safely, using ?.) from the data, and set my @Field annotated script variable, then do
if (SAVE) {
save()
}
I use "SAVE" instead of "DRY_RUN" because of the psychology behind it: you must actively decide to save. With "DRY_RUN", you must actively decide to NOT save. With, "SAVE", if you forget to set the variable, then it doesn't save. You change the variable and re-run the script. With "DRY_RUN", if you forget to set it to true, you start accidentally saving, causing potential data corruption.
It takes some thinking when developing the script, but this is the easiest pattern to use right now. It maybe nice to have some global option (like a checkbox or something), but there are plenty of workarounds. I recommend taking a stab at implementing it yourself, if you want.
It would be great if Groovy Console could provide a dry-run method. So some second button to run the script without saving any changes.
This could be done by using a wrapper around the used ResourceResolver and its session object. This could then ignore calls to resolver.commit() and session.save().
On the other hand, for non-dry-runs the session.save() could be called directly by Groovy Console. This way there is no more need for session.save() at the end of all scripts.
Bindings also need to know about the dry-run. So the information needs to be provided to them, too.
The text was updated successfully, but these errors were encountered: