Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to send survey to a user once per a week

nayeemsk263
Tera Contributor

Hello All,

 

We have a requirement to send survey to user once a week for all his incident resolved in that week

1 REPLY 1

Amit Gujarathi
Giga Sage

HI @nayeemsk263 ,
I trust you are doing great.

  1. Create a new table to store survey responses:

    • Name the table as "Survey Responses".
    • Add fields such as "User" (reference to User table), "Incident" (reference to Incident table), "Rating" (integer field for survey rating), and any other relevant fields.
  2. Create a Business Rule to trigger the survey workflow:

    • Write a Business Rule on the Incident table's "State" field.
    • Set the conditions to trigger the Business Rule when an incident is resolved.
    • In the Business Rule script, schedule a workflow to send the survey to the user.
  3. Create a workflow to send the survey:

    • Define a new workflow in ServiceNow's Workflow Editor.
    • Set the "Run" field to "Scheduled" and configure it to run weekly.
    • Add an "Email" activity to send the survey email to the user.
    • Include the survey questions and a link for the user to submit their responses.
    • On completion of the workflow, create a new survey response record in the "Survey Responses" table.

Here's an example code snippet for the Business Rule:

(function executeRule(current, previous) {
  // Check if incident is resolved
  if (current.state === 7) {
    // Schedule the survey workflow
    var surveyWorkflow = new GlideRecord('wf_workflow');
    if (surveyWorkflow.get('name', 'Survey Workflow')) {
      var schedule = new GlideSchedule();
      schedule.setFixed();
      schedule.setRecurrence(1); // Weekly recurrence
      schedule.setType('W');
      
      var workflowContext = new GlideScriptableWorkflowContext(current);
      var workflow = workflowContext.newWorkflow();
      workflow.scratchpad.schedule = schedule;
      workflow.scratchpad.user = current.caller_id.toString();
      workflow.scratchpad.incident = current.sys_id.toString();
      workflow.startFlow(surveyWorkflow.sys_id.toString(), workflowContext);
    }
  }
})(current, previous);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi