Reputation: 27
I need help with a script, I have already had help before on this platform with this script. It's a protection script based on a day and different range.
At the moment : it per month (1-32 day) Is it possible to set the day of the year (1-365) ? It will work better in my script.
function AddProtectionToColumn() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var range = GetRange(ss);
var protectSs = range.protect().setDescription('Protection automatique');
var me = Session.getEffectiveUser();
protectSs.addEditor(me);
protectSs.removeEditors(protectSs.getEditors());
if (protectSs.canDomainEdit()) {
protectSs.setDomainEdit(false);
}
}
function GetRange(ss){
var today = new Date().getDate();
var protections = ss.getSheets()[0].getProtections(SpreadsheetApp.ProtectionType.RANGE);
if (today == 289){ // day of the year
return ss.getRange("J1:K4");
}
else if (today == 299){
return ss.getRange("J5:K10");
}
}
Thank you for your help!
Upvotes: 0
Views: 83
Reputation: 64032
Getting the day of the year
parseInt(Utilities.formatDate(new Date(),Session.getScriptTimeZone(), "D"));
So in your code:
function GetRange(ss){
var today = parseInt(Utilities.formatDate(new Date(),Session.getScriptTimeZone(), "D"));
var protections = ss.getSheets()[0].getProtections(SpreadsheetApp.ProtectionType.RANGE);
if (today == 289){ // day of the year
return ss.getRange("J1:K4");
}
else if (today == 299){
return ss.getRange("J5:K10");
}
}
Upvotes: 1