Trigger Survey Using Script

kumaar
Tera Contributor

I have a survey created. I want to to trigger it only  when the hr case is closed by the  user of the assignment group "Tier1"

So any of the user from the assignment group changes the state to close complete the survey named as "Survey for HR Case" will be triggering.

 

Is there any way of achieving this..if yes

Pls provide me the sample code.

 

Thankyou 

8 REPLIES 8

@kumaar 

you need not worry on that, it's at platform level and we won't find it

But it does work.

share your script

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

(function executeRule(current, previous /*null when async*/) {

    

   

    var groupSysId = current.assignment_group; // or current.assignment_group.sys_id if you prefer

    

    var tierGroups = [

        'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // sysid

        'yyyyyyyyyyyyyyyyyyyyyyyyyyyyy' // sys_id 

    ];

    var grMember = new GlideRecord('sys_user_grmember');

    grMember.addQuery('user', current.sys_updated_by);

    grMember.addQuery('group', 'IN', tierGroups.join(','));

    grMember.query();

    if (grMember.hasNext()) {

       

        var assessment = new SNC.AssessmentCreation();

        assessment.createAssessments('sysid of survey', '', current.opened_for.toString());

    }

})(current, previous);

@kumaar 

you should pass the record sysId against which the Survey has to trigger

if your BR is on HR case then it should send HR case sysId

        assessment.createAssessments('sysid of survey', current.getUniqueValue(), current.opened_for.toString());

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

I have configured an after update BR..attached the screenshot below.

Still the survey is not triggering.

Not sure where the br is going wrong