- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 04:19 AM
Hi All,
Need to trigger a notification in a Pm_project table. we have filed called Percentage complete in Pm_project table and we have form section which is Status report under this they will create record in project_status table,
My trigger condition IS. if below condition met notification should trigger.
Status Report not submitted in the last 7 days
Percent Complete not updated in the last 7 days
Please suggest,
Thank you all.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 05:23 AM
is that table "pm_project" audited?
If yes then you can use advanced notification condition and use script, I assume your notification is on pm_project table
1) query sys_audit table and see when was the last update to Percent complete
2) in the same advanced notification condition script, query status report table for this Project and see if any record was created or not in last 7 days
based on that set answer=true to send email
something like this but please enhance
var projectId = current.sys_id;
var sevenDaysAgo = new GlideDateTime();
sevenDaysAgo.addDaysUTC(-7); // Get the date 7 days ago
// Check if "Percent Complete" was updated in the last 7 days
var percentCompleteUpdated = false;
var auditGR = new GlideRecord('sys_audit');
auditGR.addQuery('tablename', 'pm_project'); // Table name
auditGR.addQuery('fieldname', 'percent_complete'); // Field name
auditGR.addQuery('documentkey', projectId); // Project sys_id
auditGR.addQuery('sys_created_on', '>=', sevenDaysAgo); // Changes within last 7 days
auditGR.query();
if (auditGR.hasNext()) {
percentCompleteUpdated = true; // Found an update for "Percent Complete"
}
// Check if a status report was submitted in the last 7 days
var statusReportSubmitted = false;
var statusReportGR = new GlideRecord('project_status');
statusReportGR.addQuery('project', projectId); // Filter by current project
statusReportGR.addQuery('sys_created_on', '>=', sevenDaysAgo); // Submitted within last 7 days
statusReportGR.query();
if (statusReportGR.hasNext()) {
statusReportSubmitted = true; // Found a status report submission
}
// Trigger notification if both conditions are not met
if (!percentCompleteUpdated && !statusReportSubmitted) {
answer = true;
} else {
answer = false;
}
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
04-08-2025 03:20 AM
Thanku @Ankur Bawiskar ,
Can we send weekly once the notification using schedule job with below script.
var projectId = current.sys_id; var sevenDaysAgo = new GlideDateTime(); sevenDaysAgo.addDaysUTC(-7); // Get the date 7 days ago // Check if "Percent Complete" was updated in the last 7 days var percentCompleteUpdated = false; var auditGR = new GlideRecord('sys_audit'); auditGR.addQuery('tablename', 'pm_project'); // Table name auditGR.addQuery('fieldname', 'percent_complete'); // Field name auditGR.addQuery('documentkey', projectId); // Project sys_id auditGR.addQuery('sys_created_on', '>=', sevenDaysAgo); // Changes within last 7 days auditGR.query(); if (auditGR.hasNext()) { percentCompleteUpdated = true; // Found an update for "Percent Complete" } // Check if a status report was submitted in the last 7 days var statusReportSubmitted = false; var statusReportGR = new GlideRecord('project_status'); statusReportGR.addQuery('project', projectId); // Filter by current project statusReportGR.addQuery('sys_created_on', '>=', sevenDaysAgo); // Submitted within last 7 days statusReportGR.query(); if (statusReportGR.hasNext()) { statusReportSubmitted = true; // Found a status report submission } // Trigger notification if both conditions are not met if (!percentCompleteUpdated && !statusReportSubmitted) { answer = true; } else { answer = false; }
Please suggest.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 04:39 AM - edited 04-07-2025 04:40 AM
Hi @varma2 ,
Just to clarify status report is not form section. It’s a related list and the field percentage complete is in project_status table and not in pm_project table. So you need to set a trigger condition in project_status table.
Just check if you can set you above trigger condition through email notification record inserted.
If my response helped, then mark my response as solution accepted and hit thumbs up.
Regards,
Rohit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 05:01 AM
Hi @Rohit Singh
Thank you for your response.
Yes, we can set the condition but how can we give time stamp in condition,
Status Report not submitted in the last 7 days
Percent Complete not updated in the last 7 days
Please suggest.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 05:23 AM
is that table "pm_project" audited?
If yes then you can use advanced notification condition and use script, I assume your notification is on pm_project table
1) query sys_audit table and see when was the last update to Percent complete
2) in the same advanced notification condition script, query status report table for this Project and see if any record was created or not in last 7 days
based on that set answer=true to send email
something like this but please enhance
var projectId = current.sys_id;
var sevenDaysAgo = new GlideDateTime();
sevenDaysAgo.addDaysUTC(-7); // Get the date 7 days ago
// Check if "Percent Complete" was updated in the last 7 days
var percentCompleteUpdated = false;
var auditGR = new GlideRecord('sys_audit');
auditGR.addQuery('tablename', 'pm_project'); // Table name
auditGR.addQuery('fieldname', 'percent_complete'); // Field name
auditGR.addQuery('documentkey', projectId); // Project sys_id
auditGR.addQuery('sys_created_on', '>=', sevenDaysAgo); // Changes within last 7 days
auditGR.query();
if (auditGR.hasNext()) {
percentCompleteUpdated = true; // Found an update for "Percent Complete"
}
// Check if a status report was submitted in the last 7 days
var statusReportSubmitted = false;
var statusReportGR = new GlideRecord('project_status');
statusReportGR.addQuery('project', projectId); // Filter by current project
statusReportGR.addQuery('sys_created_on', '>=', sevenDaysAgo); // Submitted within last 7 days
statusReportGR.query();
if (statusReportGR.hasNext()) {
statusReportSubmitted = true; // Found a status report submission
}
// Trigger notification if both conditions are not met
if (!percentCompleteUpdated && !statusReportSubmitted) {
answer = true;
} else {
answer = false;
}
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
04-08-2025 03:20 AM
Thanku @Ankur Bawiskar ,
Can we send weekly once the notification using schedule job with below script.
var projectId = current.sys_id; var sevenDaysAgo = new GlideDateTime(); sevenDaysAgo.addDaysUTC(-7); // Get the date 7 days ago // Check if "Percent Complete" was updated in the last 7 days var percentCompleteUpdated = false; var auditGR = new GlideRecord('sys_audit'); auditGR.addQuery('tablename', 'pm_project'); // Table name auditGR.addQuery('fieldname', 'percent_complete'); // Field name auditGR.addQuery('documentkey', projectId); // Project sys_id auditGR.addQuery('sys_created_on', '>=', sevenDaysAgo); // Changes within last 7 days auditGR.query(); if (auditGR.hasNext()) { percentCompleteUpdated = true; // Found an update for "Percent Complete" } // Check if a status report was submitted in the last 7 days var statusReportSubmitted = false; var statusReportGR = new GlideRecord('project_status'); statusReportGR.addQuery('project', projectId); // Filter by current project statusReportGR.addQuery('sys_created_on', '>=', sevenDaysAgo); // Submitted within last 7 days statusReportGR.query(); if (statusReportGR.hasNext()) { statusReportSubmitted = true; // Found a status report submission } // Trigger notification if both conditions are not met if (!percentCompleteUpdated && !statusReportSubmitted) { answer = true; } else { answer = false; }
Please suggest.
Thank you