How are people handling sandbox refreshes removing...
# suitescript
b
How are people handling sandbox refreshes removing the schedules for schedule script deployments? Does anyone have a clever way to update the schedules in bulk? Very frustrating for us, we have over 200 scheduled scripts running.
😧 1
w
1. Go into the production environment and navigate to any record-page. 2. Open the developer tools in Chrome 3. Run this code in the console:
Copy code
require(['N/search'], function(search) {
try {      
    var s=search.create({
	      type: "scriptdeployment",
        filters: [ ["status","anyof","SCHEDULED"] ]
    });
    const ids = []
    s.run().each(function(r){
        ids.push(r.id)
        return true;
    });
    console.log(ids)
} catch(e){console.error(e.message);}})
3. This will output a list of ids for Script deployments that are scheduled. Copy this list. 4. Log in to the sandbox environment and navigate to any record-page 5. Run this code in the console:
Copy code
require(['N/record'], function(record) {
[paste,the,comma,separated,list,of,ids,from,step,4,between,the,brackets].forEach(id => {
  const rec = record.load({ type: record.Type.SCRIPT_DEPLOYMENT, id })
  rec.setValue({fieldId: 'status', value: 'SCHEDULED'})
  rec.save()
})
})
6. Verify that you now have an equal number of scripts that are scheduled in the sandbox as in production
b
I’m doing a little dance over here! Thanks Watz, I’ll try it out and report back
w
With 200 scripts, you might need to split the list of ids and run first part, refresh page and run the other part. You have 1000 units in the client, and I don’t know the usage for loading and saving at script deployment off the top of my head.
👍 1
e
We use SDF+git. After a refresh, we deploy our main branch with SDF to the sandbox, and everything is in the state we want.
b
I’m not a dev - just a clever admin. @Watz I kept getting errors from your second code snip. I think I am the problem as I wasn’t super sure where to put the array I got from step one. @erictgrubaugh I am love SDF and hadn’t thought of that. It was actually super simple to create a project based off of my prod account and update the sandbox - after a few errors (mainly missing start dates for inactive schedules) Thanks to you both!
1
w
Ah, maybe I should've written that you need to wrap the last code in a require as well. I'll update the snippet.
b
Thanks @Watz It moves a step further but throws this error