Survey Trigger
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hello everyone,
We currently have a public survey that has been in use for some time. A new requirement has come up: the survey now needs to be sent automatically based on a specific trigger.
Relevant Tables:
pm_project
pm_project_task
pm_m2m_project_stakeholder
Trigger Conditions
The project may have one or more stakeholders defined in the Stakeholder tab.
Stakeholders who should receive the survey have the field assessment = "yes".
The project contains multiple project tasks, and one of those tasks is "Installation Milestone".
Requirement
When the "Installation Milestone" task reaches the state Close Complete, the system should automatically send the survey to all stakeholders on the project where assessment = "yes".
I’m looking for guidance on how to implement this trigger logic.
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @CV1
May you consider create an After>Update Business Rule on pm_project_task
Condition: task name = Installation Milestone and state changes to Close Complete
From the task, get the related project
Query pm_m2m_project_stakeholder where project = current project and assessment = yes
Send the survey to each returned stakeholder
That’s all that’s needed for the trigger logic.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @CV1
Try once with this:
Create a After update Business rule:
- Name: Send Survey on Installation Milestone
- Table: Project Task (pm_project_task)
- When: after
- Update: Check
- Condition :
[Short description] [is] [Installation Milestone] AND
[State] [is] [Close Complete]
- Advanced: Check the Advanced box.
Sample Script
(function executeRule(current, previous /*null when async*/) {
if (current.short_description != 'Installation Milestone' || current.state != '3') { //Assuming 3 is Close Complete
return;
}
var projectSysId = current.project.toString();
var surveySysId = '<YOUR_SURVEY_SYS_ID>'; // Replace with your actual Assessment/Survey sys_id
var stakeholderGR = new GlideRecord('pm_m2m_project_stakeholder');
stakeholderGR.addQuery('project', projectSysId);
stakeholderGR.addQuery('assessment', 'yes');
stakeholderGR.query();
while (stakeholderGR.next()) {
var stakeholderId = stakeholderGR.stakeholder.toString(); // Ref field to User : sys_ids of users to send assessment or survey
var result = new SNC.AssessmentCreation().createAssessments(surveySysId, projectSysId, stakeholderId);
}
})(current, previous);
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
Tried this but the BR is not triggering.