- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2025 05:37 AM
Good evening.
I have a Catalog Form "New Colleague", where we enter user details and emails are triggered.
For new colleagues, condition should be that, created on today, start date should be 3 days ago in the past or start date should be 28 days in the future.
But start date filter condition is fetching incorrect records. I don't know why. For new users, RITM and REQTASK should get created and, for existing colleagues, no REQTASK should be created.
The only difference to differentiate new and exisiting users is below:
creation date is current and start date is from up to 3 days in the past and up to 28 days in future
The issue is, for existing users, workflow should give "yes", but it is getting stuck at one point and a Script include error is coming in workflow., and for new users, it gives "no", and workflow is going ahead smooth. Please check the script and help me.
Will you please check what this code is doing?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2025 05:48 AM
Hello @AbdurRahmanSnow
gs.dateDiff - can you instead use this one ? Return it in seconds and compare exact values.
This will reduce a lot of script lines and debugging will also become easy.
Kindly mark my answer as helpful and accept solution if it helped you in anyway,
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2025 05:57 AM
try this
answer = ifScript();
function ifScript() {
var date;
var user = current.variables.requested_for;
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", user);
gr.addEncodedQuery('active=true^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
gr.query();
if (gr.next()) {
date = gr.sys_created_on;
gs.info("User " + gr.name + " User creation date " + date);
}
var nowTime = new GlideDateTime(date).getDate();
var dateField = new GlideDateTime(current.variables.start_date).getDate();
var c_date = new GlideDate();
var dur1 = GlideDate.subtract(nowTime, c_date).getDayPart();
if (dur1 == 0) {
gs.info("Start Date of field " + dateField);
gs.info("Creation date trimming time " + nowTime);
var dur = GlideDateTime.subtract(nowTime, dateField);
var days = dur.getDayPart();
gs.info("Real time " + days);
if (days >= -3 && days <= 28)
return 'no';
}
return 'yes';
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2025 05:48 AM
Hello @AbdurRahmanSnow
gs.dateDiff - can you instead use this one ? Return it in seconds and compare exact values.
This will reduce a lot of script lines and debugging will also become easy.
Kindly mark my answer as helpful and accept solution if it helped you in anyway,
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2025 05:57 AM
try this
answer = ifScript();
function ifScript() {
var date;
var user = current.variables.requested_for;
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", user);
gr.addEncodedQuery('active=true^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
gr.query();
if (gr.next()) {
date = gr.sys_created_on;
gs.info("User " + gr.name + " User creation date " + date);
}
var nowTime = new GlideDateTime(date).getDate();
var dateField = new GlideDateTime(current.variables.start_date).getDate();
var c_date = new GlideDate();
var dur1 = GlideDate.subtract(nowTime, c_date).getDayPart();
if (dur1 == 0) {
gs.info("Start Date of field " + dateField);
gs.info("Creation date trimming time " + nowTime);
var dur = GlideDateTime.subtract(nowTime, dateField);
var days = dur.getDayPart();
gs.info("Real time " + days);
if (days >= -3 && days <= 28)
return 'no';
}
return 'yes';
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2025 07:14 AM
Ankur, there is also a Scheduled Job that runs in the background for every 15 min. Please check this code too. Even, this might cause the issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2025 07:58 AM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader