How do I Display Trigger record details(number ,short description...) on Survey In service Portal?

GM5
Giga Guru

Hello everyone, I'm trying to show the Trigger Record number and short description on the top of a survey, for example if the survey was triggered by an Incident I would love to see the INC number and Short description at the top, my first thought was to check the service portal widget  to see if there any option/setting to do this but unfortunately I couldn't find any, checking the widget [Survey and Assessments]

I did not  see any fields or something on the HTML it appears that it renders the contents of the " assessment_take2 " UI page in portal, I decided to play with it and I was able to print some stuff, however when I try to bring the Record number and short description I got a undef message. see Image 1.

I tried using this code To get the TiggerID Record number usually it display like this (on my code I remove the : ) 

GM5_0-1678158767094.png

 



<g:evaluate var="jvar_task_number">
			var gr = new GlideRecord("asmt_assessment_instance");
			gr.get(instance);
			var task_number= "";
			itask_number = gr.getDisplayValue('trigger_id').split(': ')[1];
			instance_number;
</g:evaluate>


<!-- few lines later near the main header I add this  just near the <class="assessment"> div -->

<div>
   <h1>${jvar_task_number}</h1>
</div>

 

And I get the following Error:

GM5_1-1678159238856.png



However if I hardcode the SysID on the jelly part I get the results I want:

GM5_2-1678159308821.png


Even I can pull the Short Description:

GM5_3-1678160023253.png

 

Unfortunatelly I lack of experience in Jelly I have no idea why using "instance" which is defined all over the code and used on other OOTB lines works but not on mine. here some example:

This block of code comes out of the box:

GM5_4-1678160141703.png



And when I print it I get results like:

 

GM5_5-1678160203953.png

 

 

 

Also this is only working on Default view not Portal and is required there but no clue, please help.

 

Please do not suggest these posts none of their code works these articles are pretty old. I already consumed time reading them.

 

https://www.servicenow.com/community/developer-forum/how-to-display-incident-number-and-short-descri...

https://www.servicenow.com/community/now-platform-forum/showing-trigger-id-record-on-survey/m-p/1062...

 

1 ACCEPTED SOLUTION

GM5
Giga Guru

With the help of a colleague we found a way to make this work in portal view, customer want this only on Service Portal so I'll ignore the self-service view portion.



 

 

  1. Go to service portal and create a new empty widget
    • On Server Script add the following:

 

 

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
    var instanceId = $sp.getParameter('instance_id');   
    data.assessment = $sp.getAssessmentRecord(instanceId, '', data);
    
})();​

 

 

  • On HTML template add the following:
<div class="panel panel-default">
  <div class="panel-heading">Survey Details</div>
  <div class="panel-body">     
    <div ng-if="data.assessment.trigger_id" style="font-size:15px;">
      {{::data.assessment.evaluation_method_display}} ${is in reference to}      
      <a href="?id=ticket&table={{::data.assessment.trigger_table}}&sys_id={{::data.assessment.trigger_id}}">{{::data.assessment.trigger_display}}</a> 
      <div style="font-size:15px;">
        {{::data.assessment.trigger_desc}}
      </div>
    </div>
  </div>
</div>

 

 

 

  • Save and publish your widget
  • Go to Sevice Portal page editor and look for "take_assessment"  page
  • On "take_assessment" page drag and drop your custom widget on top of the "Survey and assessments" widget 
  • Assign yourself a valid survey ( The assessment instance must have a valid trigger ID other wise this won't work)
  • **Important make sure to change your scope to Service Portal Survey 

GM5_0-1678207963992.png

 

View solution in original post

6 REPLIES 6

GM5
Giga Guru

With the help of a colleague we found a way to make this work in portal view, customer want this only on Service Portal so I'll ignore the self-service view portion.



 

 

  1. Go to service portal and create a new empty widget
    • On Server Script add the following:

 

 

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
    var instanceId = $sp.getParameter('instance_id');   
    data.assessment = $sp.getAssessmentRecord(instanceId, '', data);
    
})();​

 

 

  • On HTML template add the following:
<div class="panel panel-default">
  <div class="panel-heading">Survey Details</div>
  <div class="panel-body">     
    <div ng-if="data.assessment.trigger_id" style="font-size:15px;">
      {{::data.assessment.evaluation_method_display}} ${is in reference to}      
      <a href="?id=ticket&table={{::data.assessment.trigger_table}}&sys_id={{::data.assessment.trigger_id}}">{{::data.assessment.trigger_display}}</a> 
      <div style="font-size:15px;">
        {{::data.assessment.trigger_desc}}
      </div>
    </div>
  </div>
</div>

 

 

 

  • Save and publish your widget
  • Go to Sevice Portal page editor and look for "take_assessment"  page
  • On "take_assessment" page drag and drop your custom widget on top of the "Survey and assessments" widget 
  • Assign yourself a valid survey ( The assessment instance must have a valid trigger ID other wise this won't work)
  • **Important make sure to change your scope to Service Portal Survey 

GM5_0-1678207963992.png

 

sp00789992
Tera Contributor

Its perfect solution.

Thank you.

Vadzim Surin1
Tera Expert

Hi @GM5 ,
Do you have any information how the '$sp.getAssessmentRecord' function works?
We are trying to show survey result on the portal to other user than user passed a survey. We have investigated that $sp.getAssessmentRecord doesn't retrieve survey data for the user who didn't pass a survey. We still cannot find where the restriction is.

Hi @Vadzim Surin1 ,

Did you ever figure this out? I'm also trying to show the assessment quiz score/result on the service portal when they take it.  Thanks.