General Help with surveys and users

Max Beil
Tera Contributor

Hello All, 

A simple question that I'm stuck on and couldn't find an answer to.

I created a Survey that is sent to Contacts in the ServiceNow system (they get a mail with a link to the survey)
when they open the survey a Survey instance is created.

is there any way to automatically get the name or email of the user that opened the survey and match\update it to the instance of that survey?

 

2 ACCEPTED SOLUTIONS

Rahul Kumar17
Tera Guru

Hi,

 

 

Here are the steps:

  1. Create a new field (e.g., "Contact Email") on the Survey [asmt_metric_instance] table to store the email of the user who responded to the survey.
  2. Modify the URL of the survey invitation email to include the email of the contact as a parameter (e.g., https://<yourinstance>.service-now.com/<survey_url>?email=<contact_email>).
  3. In the Survey [asmt_metric_instance] table, create a new Business Rule that triggers on "Insert" and "Update" actions.
  4. In the Business Rule script, use the "current" variable to get the email address of the user who responded to the survey from the "email" parameter in the URL.
  5. Set the value of the "Contact Email" field to the email address of the user who responded to the survey.

Here is an example Business Rule script:

 

 

 

(function executeRule(current, previous /*null when async*/) {
   // Get the email address of the contact from the URL parameter
   var contactEmail = current.variables.u_survey_url.getURLParameter('email');
   
   // Set the value of the "Contact Email" field
   current.u_contact_email = contactEmail;
})(current, previous);

 

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

View solution in original post

Ludmila Spector
Mega Guru
Mega Guru

@Max Beil Out of the box, there is 'Assigned To' field on the asmt_assessment_instance table. It should contain the user (ref to sys_user table) who survey was sent to. I believe responder should be the same user as the recipient of the survey, SN security will prevent someone else from taking it.

Maybe you are doing something with anonymous surveys, in which case the solution above provided by Rahul Kumar should do the trick.

View solution in original post

4 REPLIES 4

Rahul Kumar17
Tera Guru

Hi,

 

 

Here are the steps:

  1. Create a new field (e.g., "Contact Email") on the Survey [asmt_metric_instance] table to store the email of the user who responded to the survey.
  2. Modify the URL of the survey invitation email to include the email of the contact as a parameter (e.g., https://<yourinstance>.service-now.com/<survey_url>?email=<contact_email>).
  3. In the Survey [asmt_metric_instance] table, create a new Business Rule that triggers on "Insert" and "Update" actions.
  4. In the Business Rule script, use the "current" variable to get the email address of the user who responded to the survey from the "email" parameter in the URL.
  5. Set the value of the "Contact Email" field to the email address of the user who responded to the survey.

Here is an example Business Rule script:

 

 

 

(function executeRule(current, previous /*null when async*/) {
   // Get the email address of the contact from the URL parameter
   var contactEmail = current.variables.u_survey_url.getURLParameter('email');
   
   // Set the value of the "Contact Email" field
   current.u_contact_email = contactEmail;
})(current, previous);

 

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

@Max Beil 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

I will check your solution soon and will close the thread after,
Thank you for the amazing explanation and step by step guide!

Ludmila Spector
Mega Guru
Mega Guru

@Max Beil Out of the box, there is 'Assigned To' field on the asmt_assessment_instance table. It should contain the user (ref to sys_user table) who survey was sent to. I believe responder should be the same user as the recipient of the survey, SN security will prevent someone else from taking it.

Maybe you are doing something with anonymous surveys, in which case the solution above provided by Rahul Kumar should do the trick.