survey_reader users get error when clicking View User's Response UI Action

galavodasal
Giga Expert

We opened up the "View User's Response" UI Action so that you didn't need the survey_admin role to use the UI Action. The UI Action works for survey_reader users in dev, but our dev environment is Jakarta Patch 4, and our production environment is still on Istanbul.

survey_reader users in production get this message when clicking the "View User's Response" UI Action :

There was an unexpected failure with this assessment, invalid type provided

If we give the users survey_admin in production, the UI Action works. Here's the updated UI Action. Again, all we removed was the survey_admin role from the roles list:

find_real_file.png

find_real_file.png

3 REPLIES 3

Niclas
Giga Guru

We just came across the same question It doesn't really is logical why this feature is limited to Survey Admins out of the box.



At first you should replace line 3


var type = g_form.getReference("metric_type")


with


var type = g_form.getValue("metric_type")



Explanation:


  • g_form.getReference will return a Client-Side GlideRecord. However in line 4 you can see that we only need to set a sys-id in the URL. It doesn't make sense to set a GlideRecord Object as URL parameter and i guess it fails for the survey_reader due to some access rights issues
  • Due to ServiceNow Best Practices it is not recommend to use g_form.getReference without an callback function anyway. Without a callback function, g_form.getReference runs synchronously and processing will halt (causing the browser to appear to hang) while waiting on a server response.


So this will fix the first issue. But there is another issue now:


You are not authorized to take this survey



To fix this error you would need to adjust the UI Page assessment_take2.   Replace the following out-of-the-box line in the HTML field (should be somewhere around line 72)



if ('${sysparm_isSurveyCreator}' == 'yes' || ('${jvar_isReaderView}' == 'true' ${AND} gs.hasRole('survey_admin')))



with:


if ('${sysparm_isSurveyCreator}' == 'yes' || ('${jvar_isReaderView}' == 'true' ${AND} gs.hasRole('survey_reader')))




NOTE: The survey_admin would still have access to the "View User respones", as it should include the survey_reader role out-of-the-box. Make sure it is the case on your instance, somehow it wasn't on mine. If your survey_admin role does not contain the survey_reader role, you can use that line:



if ('${sysparm_isSurveyCreator}' == 'yes' || ('${jvar_isReaderView}' == 'true' ${AND} (gs.hasRole('survey_admin')) || gs.hasRole('survey_reader')))


This was spot on! Helped me resolve this issue fairly quickly. Thank you!

Nice, thank you!

My code is a little different (bold).
I used this line:

if (jelly.sysparm_isSurveyCreator == 'yes' || (jelly.jvar_isReaderView == 'true' ${AND} (gs.hasRole('survey_admin')) || gs.hasRole('survey_reader')))

 

instead:

if ('${sysparm_isSurveyCreator}' == 'yes' || ('${jvar_isReaderView}' == 'true' ${AND} (gs.hasRole('survey_admin')) || gs.hasRole('survey_reader')))