Hi
I am not a programmer, but have tried to make some code to update the data repository with a deletion code, if the records are modified a certain amount of days ago. However, I cannot get it to work, and it seems like my problem is to get the “DateM” Modified date out of the repository and into my variable. In the repository the “DateM” is in a lighter gray, if that is a hint to why.
Hope someone can help guiding me in the right direction.
This is the code
/Repository variables/
var Repo = new ActiveXObject(‘RepositoryLib.WorkflowRepository’);
//var PrintJob = Repo.GetKeySets(“olfw_files”, ‘[“jobid”, “stateid”, “marked_delete”, “DateM”]’);
var PrintJob = Repo.GetKeySets(“olfw_files”, ‘*’);
/date now/
var dateNow = new Date();
var month = dateNow.getUTCMonth() + 1; //months from 1-12
var day = dateNow.getUTCDate();
var year = dateNow.getUTCFullYear();
newDate = year + “/” + month + “/” + day;
// only run if data repository group is not empty.
if (PrintJob.length != 0) {
for (var x=0; x < PrintJob.length; x++) {
/*modifyed date*/
//var modifyedDate = new Date((PrintJob[x].DateM).replace('-', '/'));
var modifyedDate = new Date((PrintJob[x].DateM));
//var test1 = PrintJob[x].DateM; //test
/*Date dif*/
var TimeDif = Math.abs(newDate - modifyedDate);
var DaysDif = Math.ceil(TimeDif / (1000 * 60 * 60 * 24));
var JobID = PrintJob[x].jobid;
Watch.log('NewDate: ' + newDate, 3);
Watch.log('ModifyDate: ' + modifyedDate, 3);
Watch.log('Dagif: ' + DaysDif, 3);
Watch.log('Jobid: ' + JobID, 3);
//watch.log('ModifyDate: ' + test1, 3); //test
if (PrintJob[x].stateid == 30 && DaysDif >= 14) {
Repo.SetValueByID("olfw_files", "marked_delete", "1", JobID);
} else if (PrintJob[x].stateid == 40 && DaysDif >= 7) {
Repo.SetValueByID("olfw_files", "marked_delete", "1", JobID);
}
}
}
Best regards
Thomas