Survey Trigger

CV1
Tera Contributor

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

  1. The project may have one or more stakeholders defined in the Stakeholder tab.

    • Stakeholders who should receive the survey have the field assessment = "yes".

  2. 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

3 REPLIES 3

Rafael Batistot
Kilo Patron

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.

 

If this response was helpful, please mark it as Helpful and, if applicable, as Correct, this helps other users find accurate and useful information more easily.

Tanushree Maiti
Tera Patron

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);

 

 

Refer: https://www.servicenow.com/community/developer-forum/quot-create-user-survey-quot-ui-action/m-p/2163...

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Tried this but the BR is not triggering.