Survey - script to put in Introduction to display the INC# and the Date the INC was opened.

Linda Kendrick
Kilo Guru

In the introduction of the survey would like to display the INC# and short description with the date the Incident was opened. Do I do a Client Script and set the introduction field to the text needed?

Thank you for contacting the Service Desk on [DATE].
Please take a moment and rate your recent interaction regarding Incident [NUMBER]: [SHORT DESCRIPTION].

1 ACCEPTED SOLUTION

Rodrigo Higa
Kilo Guru

Hi Linda,



Client Script wont ´t work for Survey purpose.



As mentioned by Aaron, you will need to request the Plugin "Survey Wizard", that will bring to you the application "Wizard Client Script".



I have done a similar functionality in a Survey Introduction.



After this plugin enabled, I created a Wizard Client Script, as "On Load" type, with the following script, try it:



function onLoad() {


     


      var params = location.search.substr(location.search.indexOf("?")+1);


      var sval = "";


      params = params.split("&");


      // split param and value into individual pieces


      for (var i=0; i<params.length; i++)


              {


  if (params[i].indexOf('EV:') >=0 ) {


  temp = params[i].substr(3,params[i].length).split('=');


  } else {


  temp = params[i].split("=");


  }


  if ( [temp[0]] == 'sysparm_task_survey' ) { sval = temp[1]; }


              }


  var task_id = new GlideRecord('task_survey');


  task_id.get(sval);


  var doc = new GlideRecord('task');


  doc.get(task_id.task);


  var assigned = new GlideRecord('sys_user');


  assigned.get(doc.assigned_to);


  var titulo = doc.number + ' - ' + doc.short_description;


  var dh = doc.sys_updated_on + '';


  var fdh = dh.substr(8,2) + '/' + dh.substr(5,2) + '/' + dh.substr(0,4);// + ' ' + dh.substr(11,5);


  var detalhes = 'Assigned by: ' + assigned.name + '<br>';


  detalhes += 'Assigned on: ' + fdh;



  var elems = document.getElementsByTagName('TD'), i;


      for (i in elems) {


              if((' ' + elems[i].className + ' ').indexOf(' ' + 'catalog_description' + ' ')


                              > -1) {


                      elems[i].innerHTML = '<br><p><span style="font-family: arial, helvetica, sans-serif; font-size: large;" size="4" face="arial,helvetica,sans-serif">' + titulo + '</span><br><span> '+ detalhes + '</span></p>' + elems[i].innerHTML;


              }


      }


}



Cheers,


Rodrigo Higa


View solution in original post

3 REPLIES 3

Aaron40
Kilo Guru

Hi Linda,

I think there are a couple ways to achieve this. You might be able to add a new macro variable to the top of the survey and have the macro perform the calculation and display the text you want.

The other option I can think of is installing the Survey Wizards plugin. This will allow the introduction of client scripts to your surveys. See http://wiki.servicenow.com/index.php?title=Survey_Wizard_Plugin for more information on the plugin.


Rodrigo Higa
Kilo Guru

Hi Linda,



Client Script wont ´t work for Survey purpose.



As mentioned by Aaron, you will need to request the Plugin "Survey Wizard", that will bring to you the application "Wizard Client Script".



I have done a similar functionality in a Survey Introduction.



After this plugin enabled, I created a Wizard Client Script, as "On Load" type, with the following script, try it:



function onLoad() {


     


      var params = location.search.substr(location.search.indexOf("?")+1);


      var sval = "";


      params = params.split("&");


      // split param and value into individual pieces


      for (var i=0; i<params.length; i++)


              {


  if (params[i].indexOf('EV:') >=0 ) {


  temp = params[i].substr(3,params[i].length).split('=');


  } else {


  temp = params[i].split("=");


  }


  if ( [temp[0]] == 'sysparm_task_survey' ) { sval = temp[1]; }


              }


  var task_id = new GlideRecord('task_survey');


  task_id.get(sval);


  var doc = new GlideRecord('task');


  doc.get(task_id.task);


  var assigned = new GlideRecord('sys_user');


  assigned.get(doc.assigned_to);


  var titulo = doc.number + ' - ' + doc.short_description;


  var dh = doc.sys_updated_on + '';


  var fdh = dh.substr(8,2) + '/' + dh.substr(5,2) + '/' + dh.substr(0,4);// + ' ' + dh.substr(11,5);


  var detalhes = 'Assigned by: ' + assigned.name + '<br>';


  detalhes += 'Assigned on: ' + fdh;



  var elems = document.getElementsByTagName('TD'), i;


      for (i in elems) {


              if((' ' + elems[i].className + ' ').indexOf(' ' + 'catalog_description' + ' ')


                              > -1) {


                      elems[i].innerHTML = '<br><p><span style="font-family: arial, helvetica, sans-serif; font-size: large;" size="4" face="arial,helvetica,sans-serif">' + titulo + '</span><br><span> '+ detalhes + '</span></p>' + elems[i].innerHTML;


              }


      }


}



Cheers,


Rodrigo Higa


darreneverett
Mega Expert

You can put the survey link into the body of a standard email notifications, and have all of the email notification functionality and standards.

 

Darren