- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 10:50 AM
Hi All!
I'm working in a scheduled job to trigger a subflow to create bulk cases. Stakeholder want to create this cases on specific days, dates. (7th day of the month - 5th day of month ) .
I've created a scripted condition like below to trigger the subflow on 1st day of each month : ( on scripts - background works correctly )
answer = checkdate();
gs.info(answer);
function checkdate() {
var answer = false;
var today = new GlideDateTime('2024-03-01 18:38:34');
gs.info(' RG:: Today is: ' + today);
var endofMonth = new GlideDateTime(today);
endofMonth.setDayOfMonthLocalTime(1);
gs.info(' RG:: FIRST DAY of month is: ' + endofMonth);
var gdt = new GlideDateTime(endofMonth);
gdt.getDayOfWeekLocalTime()
gs.info(' RG:: Day of Week: ' + gdt.getDayOfWeekLocalTime());
if (gdt.getDayOfWeekLocalTime() == "6") {
var l = new GlideDateTime(endofMonth);
l.addDaysLocalTime(2);
gs.info('RG::' + l);
var dura = new GlideDuration();
dura = GlideDateTime.subtract(l, today);
var i = dura.getRoundedDayPart();
gs.info('RG::' + i);
if (i == 0) {
gs.info(' RG:: l');
answer = true;
}
// else {
// return false;
//}
} else if (gdt.getDayOfWeekLocalTime() == "7") {
var k = new GlideDateTime(endofMonth);
k.addDaysLocalTime(1);
gs.info('RG::' + k);
var durat = new GlideDuration();
durat = GlideDateTime.subtract(k, today);
var o = dur.getRoundedDayPart();
gs.info('RG::' + o);
if (o == 0) {
gs.info('RG:: k');
answer = true;
}
//else {
// return false;
//}
} else if (gdt.getDayOfWeekLocalTime() == "1" || gdt.getDayOfWeekLocalTime() == "2" || gdt.getDayOfWeekLocalTime() == "3" || gdt.getDayOfWeekLocalTime() == "4" || gdt.getDayOfWeekLocalTime() == "5") {
var h = new GlideDateTime(endofMonth);
gs.info('RG:: is day of the week ' + h);
var dur = new GlideDuration();
dur = GlideDateTime.subtract(h, today);
var u = dur.getRoundedDayPart();
gs.info('RG :SUBTRACT: ' + u);
if (u == 0) {
gs.info('RG: is equal to 0 : h');
answer = true;
}
// else {
// return false;
// }
} else {
gs.info('RG:: false');
answer = false;
}
return answer;
}
I know that the script to run the subflow works, because when I execute it without condition WORKS.
Do you know what can happen in this case ? What Im missing?
Thanks!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 12:27 PM
Hey @Gpope,
No worries, it works in my PDI, the condition is:
var answer = checkdate();
answer;
function checkdate() {
var answer = false;
var today = new GlideDateTime('2024-03-01 18:38:34');
gs.info(' RG:: Today is: ' + today);
var endofMonth = new GlideDateTime(today);
endofMonth.setDayOfMonthLocalTime(1);
gs.info(' RG:: FIRST DAY of month is: ' + endofMonth);
var gdt = new GlideDateTime(endofMonth);
gdt.getDayOfWeekLocalTime()
gs.info(' RG:: Day of Week: ' + gdt.getDayOfWeekLocalTime());
if (gdt.getDayOfWeekLocalTime() == "6") {
var l = new GlideDateTime(endofMonth);
l.addDaysLocalTime(2);
gs.info('RG::' + l);
var dura = new GlideDuration();
dura = GlideDateTime.subtract(l, today);
var i = dura.getRoundedDayPart();
gs.info('RG::' + i);
if (i == 0) {
gs.info(' RG:: l');
answer = true;
}
// else {
// return false;
//}
} else if (gdt.getDayOfWeekLocalTime() == "7") {
var k = new GlideDateTime(endofMonth);
k.addDaysLocalTime(1);
gs.info('RG::' + k);
var durat = new GlideDuration();
durat = GlideDateTime.subtract(k, today);
var o = dur.getRoundedDayPart();
gs.info('RG::' + o);
if (o == 0) {
gs.info('RG:: k');
answer = true;
}
//else {
// return false;
//}
} else if (gdt.getDayOfWeekLocalTime() == "1" || gdt.getDayOfWeekLocalTime() == "2" || gdt.getDayOfWeekLocalTime() == "3" || gdt.getDayOfWeekLocalTime() == "4" || gdt.getDayOfWeekLocalTime() == "5") {
var h = new GlideDateTime(endofMonth);
gs.info('RG:: is day of the week ' + h);
var dur = new GlideDuration();
dur = GlideDateTime.subtract(h, today);
var u = dur.getRoundedDayPart();
gs.info('RG :SUBTRACT: ' + u);
if (u == 0) {
gs.info('RG: is equal to 0 : h');
answer = true;
}
// else {
// return false;
// }
} else {
gs.info('RG:: false');
answer = false;
}
return answer;
}
If it still doesn't work, can you share a whole screenshot of the Scheduled Job (including other condition, 'run this script' section)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 12:08 PM
Hey @Gpope,
Given that the checkdate function is working, update the first two lines of the condition as below:
var answer = checkdate();
answer;
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 12:16 PM
Hi @James Chun , thanks for taking your time in responding me.
I updated this lines but still not working. This is what I get in scripts background :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 12:27 PM
Hey @Gpope,
No worries, it works in my PDI, the condition is:
var answer = checkdate();
answer;
function checkdate() {
var answer = false;
var today = new GlideDateTime('2024-03-01 18:38:34');
gs.info(' RG:: Today is: ' + today);
var endofMonth = new GlideDateTime(today);
endofMonth.setDayOfMonthLocalTime(1);
gs.info(' RG:: FIRST DAY of month is: ' + endofMonth);
var gdt = new GlideDateTime(endofMonth);
gdt.getDayOfWeekLocalTime()
gs.info(' RG:: Day of Week: ' + gdt.getDayOfWeekLocalTime());
if (gdt.getDayOfWeekLocalTime() == "6") {
var l = new GlideDateTime(endofMonth);
l.addDaysLocalTime(2);
gs.info('RG::' + l);
var dura = new GlideDuration();
dura = GlideDateTime.subtract(l, today);
var i = dura.getRoundedDayPart();
gs.info('RG::' + i);
if (i == 0) {
gs.info(' RG:: l');
answer = true;
}
// else {
// return false;
//}
} else if (gdt.getDayOfWeekLocalTime() == "7") {
var k = new GlideDateTime(endofMonth);
k.addDaysLocalTime(1);
gs.info('RG::' + k);
var durat = new GlideDuration();
durat = GlideDateTime.subtract(k, today);
var o = dur.getRoundedDayPart();
gs.info('RG::' + o);
if (o == 0) {
gs.info('RG:: k');
answer = true;
}
//else {
// return false;
//}
} else if (gdt.getDayOfWeekLocalTime() == "1" || gdt.getDayOfWeekLocalTime() == "2" || gdt.getDayOfWeekLocalTime() == "3" || gdt.getDayOfWeekLocalTime() == "4" || gdt.getDayOfWeekLocalTime() == "5") {
var h = new GlideDateTime(endofMonth);
gs.info('RG:: is day of the week ' + h);
var dur = new GlideDuration();
dur = GlideDateTime.subtract(h, today);
var u = dur.getRoundedDayPart();
gs.info('RG :SUBTRACT: ' + u);
if (u == 0) {
gs.info('RG: is equal to 0 : h');
answer = true;
}
// else {
// return false;
// }
} else {
gs.info('RG:: false');
answer = false;
}
return answer;
}
If it still doesn't work, can you share a whole screenshot of the Scheduled Job (including other condition, 'run this script' section)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2024 08:11 AM