The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Survey Trigger on Date Question

maxstnr
Tera Contributor

Hello, we're looking at using surveys for our new hires that trigger five days after they start with the organization. This does not seem to be possible with the existing trigger conditions, however. We're holding the employee's start date in their user record & they're created via SFTP import from our HRIS. What is the best way to trigger the surveys?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@maxstnr 

you can run a daily scheduled job and check how many days are there for the person to start based on date comparison.

If it's 5 days then trigger survey from script.

Something like this but please enhance with correct table and other details

AssessmentCreation - Global 

runSurvey();

function runSurvey() {
    try {
        var gr = new GlideRecord('task'); // Replace 'task' with your table name
        // Find records due in the next 5 days, including today.
        gr.addEncodedQuery('due_date>=' + gs.daysAgoStart(-5) + '^due_date<=' + gs.daysAgoEnd(0));
        gr.query();
        while (gr.next()) {
            //For creating survey instances directly from a scheduled job
            new SNC.AssessmentCreation().createAssessments('Survey Definition SysId', gr.getUniqueValue(), gr.assigned_to.toString());
        }
    } catch (ex) {
        gs.info(ex);
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@maxstnr 

you can run a daily scheduled job and check how many days are there for the person to start based on date comparison.

If it's 5 days then trigger survey from script.

Something like this but please enhance with correct table and other details

AssessmentCreation - Global 

runSurvey();

function runSurvey() {
    try {
        var gr = new GlideRecord('task'); // Replace 'task' with your table name
        // Find records due in the next 5 days, including today.
        gr.addEncodedQuery('due_date>=' + gs.daysAgoStart(-5) + '^due_date<=' + gs.daysAgoEnd(0));
        gr.query();
        while (gr.next()) {
            //For creating survey instances directly from a scheduled job
            new SNC.AssessmentCreation().createAssessments('Survey Definition SysId', gr.getUniqueValue(), gr.assigned_to.toString());
        }
    } catch (ex) {
        gs.info(ex);
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@maxstnr 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Yes, it did, we used a slightly different method but I tested using scheduled job w/ a similar script you provided & it also worked. Thank you!