How to link survey to the new ServicePortal survey view

JC S_
Mega Guru

We plan to link to the new Service Portal survey view for our existing surveys and we can't determine how to generate the instance_id on the URL to enable this.

You can already see the Service Portal survey view thru instance.service-now.com/sp?id=my_surveys

Now what we are trying to do is to automatically link the user to the relevant survey of the incident they are in when they click a notification from the mobile app or clicking the Take the Survey link on the email notification.

This is a sample URL of a specific survey that will be shown using the survey view on Service Portal (the part that is bold is the one we don't have an idea on how to generate):

instance.service-now.com/sp?id=take_survey&instance_id=4bb014670f47f2003ba0c19ce1050e28

For the mobile app notification for example, we have setup the following:

(function buildJSON(/*GlideRecord*/ current, /*String*/ message, /*Object*/ attributes) {

      var json = {};

      json = {

              "aps" : {

                      "sound" : "default"

              },

              "web_path" : "sp?id=take_survey&instance_id=" + <help needed on this part>

      };

      return json;

})(current, message, attributes);

Can someone help us determine how to get the sys_id of the survey that is related to current incident so that when user clicks the mobile app notification (or clicks the link on email address) it will show the survey using the Service Portal view.

Thanks.

1 ACCEPTED SOLUTION

JC S_
Mega Guru

We've found a solution for this after digging around and having discussions with a ServiceNow technician.



The following table stores the assessments: asmt_assessment_instance



If you personalise the list view (https://instance.service-now.com/asmt_assessment_instance_list.do), you can see there is a "Task" and "Trigger ID" column, either of them is what we need to relate the incident that spawned the survey.



Now you can modify the code in your push notification to lookup the survey (return the survey sys_id) from the "Task" that is in the "Current" incident number variable of the push notification code. You can also use the "Trigger ID" and lookup for the "Current" incident sys_id variable of the push notification code.



To do the lookup, you can add code before the "var json = {};" line to lookup the survey record associated to the incident to get the sys_id of the survey using a GlideRecord query: http://wiki.servicenow.com/index.php?title=GlideRecord#addQuery



We just modified the code I have on my original post a bit to do this lookup. Hope this helps for other users on the same situation.


View solution in original post

13 REPLIES 13

nishailame
ServiceNow Employee
ServiceNow Employee

If the question is just about determining how to get the sys_id of the survey that is related to current incident then try -> current.sys_id




ex.


var link = '<a href="https://tndev1.service-now.com/assessment_take2.do?sysparm_assessable_sysid=' + current.sys_id + '&sysparm_assessable_type=' + current.metric_type + '" target="_top">' + 'Josh is Great!' + '</a>';  



 


Thanks.


PS: Hit like, Helpful, Correct and Endorse, if it answers your question.


Hi Nisha,



We already tried current.sys_id and it does not work because what it returns in the context of a mobile push notification is the sys_id of current incident. Do note that we are talking about the service portal view of the survey and not the legacy survey view.



This is the URL format of the service portal survey view:


instance.service-now.com/sp?id=take_survey&instance_id=4bb014670f47f2003ba0c19ce1050e28



This part is what we are trying to find out on where/how to obtain when talking about mobile app push notifications:


instance_id=4bb014670f47f2003ba0c19ce1050e28


mohamudali
Kilo Contributor

Hi Jimboy, Any progress on this issue? We are experiencing the same issue to redirect survey link to portal.


Hi Mohamud, Yes we've finally found the solution to this, check it out on the correct answer I posted. You just need to take some time to understand querying GlideRecord using it to related the current incident to the survey table to get the survey sys_id. Hope this helps.