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

D_R
Giga Guru

Hi @kumaar , 

You can add the trigger condition as below(Attached screenshot)

1. State changes to complete and Assignment group is "Tier1"

Divakar_Reddy_0-1753858698326.png

 

Ankur Bawiskar
Tera Patron
Tera Patron

@kumaar 

1) create after update business rule with your matching condition and check who closed the case

2) trigger the survey from script

See for details how the result looks like at:

https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/c_AssessmentCreat...

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

Vishwa Pandya19
Mega Sage

Hi @kumaar ,

 

You will have to create a BR.

It should be an After Update BR and the condition would be State Changes To Closed Complete.

Then in the advanced section you can use the below script:

 var gr = new GlideRecord("sys_user_grmember");
    gr.addEncodedQuery("group=8a5055c9c61122780043563ef53438e3^user="+current.closed_by);
    gr.query();
    if (gr.next()) {
        var assessment = new SNC.AssessmentCreation();
//assessment.createAssessments(<sys_id of survey record>, <keep second parameter empty>, <to whom the survey will be assigned>)
        assessment.createAssessments('502a2c44d7211100158ba6859e6103a3','',current.caller_id.toString());
    }

 

If my answer has helped you in any way please mark it as correct or helpful.

I dont see AssessmentCreattion Script include in my system...

Now how to proceed with it?