Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Set survey to trigger every quarter

kim-lindgren
Kilo Sage

I have a survey I want to trigger every quarter for members of a particular group.

 

On the related list of my Survey Definition [asmt_metric_type], I can add trigger conditions, however these seem to require specific events to trigger.

 

On the Survey Definition record itself, there is the Schedule Period field, but this does not allow anything between monthly and yearly.

 

What is the solution here?

 

 

Regards,

Kim

1 ACCEPTED SOLUTION

kim-lindgren
Kilo Sage

The problem is, I did not read the docs carefully enough and I did not realize there is a difference between assessments and surveys.

https://www.servicenow.com/docs/bundle/yokohama-api-reference/page/app-store/dev_portal/API_referenc...

 

It says that the second parameter is ONLY for use with assessments. My "assessment" is actually a survey, so the second parameter should be left blank. Thus in my scheduled script:

 

triggerSurvey();

function triggerSurvey() {
    try {
        var gr = new GlideRecord("sys_user_grmember");
        gr.addQuery("group", "2ccabcccaf3d6a10e8f667caa6274980"); //Group SysID
        gr.query();
        while (gr.next()) {
            new SNC.AssessmentCreation().createAssessments('37b85f99af99ba1056b7a2c651274978' */My survey definition*/, '', gr.user);
        }

    } catch (ex) {
        gs.info(ex);
    }
}

 

Works like a charm.

View solution in original post

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

@kim-lindgren 

you can use scheduled job for this which runs every quarter and trigger survey on particular table record and for particular users

recently I shared solution for something similar on how to trigger survey from script

Schedule an assessment to be sent every quarter 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@kim-lindgren 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

M Iftikhar
Tera Sage

Hi @kim-lindgren,

 

To trigger a survey on a quarterly basis, you can use a Scheduled Script Execution instead of relying on Survey trigger conditions or the limited Schedule Period options.

Steps

  1. Navigate to System Definition > Scheduled Jobs.

  2. Click New.

  3. On the “What would you like to automate?” page, select Automatically run a script of your choosing.

    MIftikhar_0-1763569509696.png
  4. Fill out the form:

    • Name: Schedule ABC Group Survey

    • Run: Business Calendar: Entry Start

    • Business Calendar: Quarter

    • In the Run this script field, enter:
var surveyID = 'YOUR SURVEY SYSID'; 
var response = new SNC.AssessmentCreation().createAssessments(surveyID);

MIftikhar_1-1763569609881.png


This scheduled job will generate and send the survey invitations every quarter, bypassing the limitations of the Survey Definition's built-in scheduling options.

 

If my response helped, please mark it as the accepted solution so others can benefit as well.

 

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

kim-lindgren
Kilo Sage

Thanks both of you for your suggestions!

 

@M Iftikhar I went with your solution as it seemed easiest and it is working great.