Update Incident Number and other incident information on Survey Page1

chaitanyakumarD
Tera Contributor

hi I want to add an incident number and  short description on my survey form how can I achieve that my  ask is similar to that of as shown below picture but I am not able to achieve that Final result.png

similarly in the place of category I want to display short description I have found this picture in community with following code  according to the  following post in the community

https://www.servicenow.com/community/in-other-news/update-incident-number-and-other-incident-informa... 

 

here is the code :

Few things you need to change

  • You need to write jelly code in "assessment_take2" UI Page.
  • Add UI page client script variable in your survey introduction field.

Here you go..

UI Page:  

System UI >> UI Page >> search for "assessment_take2"

  • Add Jelly script in html section.

Kindly add the script before the starting of <g2:evaluate> tag. refer the screenshot below.

<!-- update incident Number on survey page -->

<g:evaluate var="jvar_task_record_sys_id">

var gr = new GlideRecord("asmt_assessment_instance");

gr.get(instance);

var task_record = "";

var task_table = "";

if(gr.trigger_table){

var tr = new GlideRecord(gr.trigger_table);

if(tr.get(gr.trigger_id)){

task_table = tr.getClassDisplayValue();

task_record = tr.getDisplayValue();

}

}

task_record;

</g:evaluate>

<!-- update incident category on survey page -->

<g:evaluate var="jvar_task_record_sys_id1">

var gr = new GlideRecord("asmt_assessment_instance");

gr.get(instance);

var inc_cat = "";

if(gr.trigger_table){

var tr = new GlideRecord(gr.trigger_table);

if(tr.get(gr.trigger_id)){

inc_cat = tr.category.getDisplayValue();

}

}

inc_cat;

</g:evaluate>

  • Adding html hidden field to save the <g:evaluate> variable value. here we need to add the html field in <g:ui_form> tag

Note:   The <g:evaluate> tag is used to evaluate an expression written in Rhino JavaScript and sometimes to set a variable to the value of the expression.The last statement in the expression is the value the variable will contain.

                                <!-- added one hidden html field -->

<input type="hidden" id="task_record_sys_id" name="task_record_sys_id" value="${jvar_task_record_sys_id}" />

<input type="hidden" id="task_record_sys_id1" name="task_record_sys_id1" value="${jvar_task_record_sys_id1}" />

chaitanyakumarD_0-1708838485642.png

 

  • In UI Page there is one section called client script ,there you need to mention the client script. the value we had saved in html field need to get into client script then we will use that variable in survey page.

gel('task_record_sys_id123').innerHTML += gel('task_record_sys_id').value;

gel('task_record_sys_id1234').innerHTML += gel('task_record_sys_id1').value;

chaitanyakumarD_1-1708838485652.png

 

  • Open the survey that you have built. just for the testing, i am going to make the changes in OOTB survey "Change Request Satisfaction Survey". there is one field called Introduction, here we will save the variable that was mentioned in your UI page client script.

Note: The introduction field is html type of field so kindly click on "source code" (icon will be "<>")   button. and paste the code below there.

<p> </p>

<table>

<tbody>

<tr>

<td>Number :</td>

<td id="task_record_sys_id123" style="color: red;"> </td>

</tr>

<tr>

<td>Category :</td>

<td id="task_record_sys_id1234" style="color: green;"> </td>

</tr>

</tbody>

</table>

<p></p>

<p> </p>

 

0 REPLIES 0