- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2023 07:39 PM
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 : )
<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:
However if I hardcode the SysID on the jelly part I get the results I want:
Even I can pull the Short Description:
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:
And when I print it I get results like:
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...
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2023 08:53 AM - edited ‎03-07-2023 08:55 AM
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.
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2025 07:27 AM - edited ‎05-05-2025 07:28 AM
Unfortunately, no.
I haven't figured out so far how the '$sp.getAssessmentRecord' function works.
One known fact - $sp.getAssessmentRecord doesn't retrieve the survey data if current user is not the user who has completed the survey.
You have to dive into server script of the 'Surveys and Assessments' widget.
Look for the line with the sp.getAssessmentRecord call:
data.assessment = $sp.getAssessmentRecord(instanceId, typeId, data);
You have to check if the _fields object has received the survey data. If not - you should add custom function call to retrieve survey data. Something like this:
data.assessment = $sp.getAssessmentRecord(instanceId, typeId, data);
if (!data.assessment._fields) {
var surveyUtils = new global.SomeSurveyUtils();
data.assessment = surveyUtils.getPortalSurveyData(instanceId);
}
Please explore the data.assessment object for the user who has completed the survey.
You can do it directly in the browser debugger.
You have to implement the 'getPortalSurveyData' as the function that would repeat the structure of survey data object just as it would for the user who has completed the survey.
On our project we use the following OOTB tables to store survey data:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2025 08:19 AM
Thanks for the update, i'll try digging into that this week. I don't understand why SN hasn't created a way to do this natively from the assessment metric type. Something like this should be basic platform feature.
Each questions score is automatically included/stored in the asmt_assessment_instance_question and asmt_metric_definition tables, and I'm also rolling up the total score to the actual assessment instance itself. If i can't get this to work, i'm considering just generating an email with the score to indicate whether the user passed or not. Which, i would probably want to do anyways. I just would prefer to also have it indicate onscreen for the user too immediately like every other modern online quiz LOL.