- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2015 07:04 AM
Using an UI action (button) from an incident I need open an Order Guide and pass a few of the incident fields like short description and caller into the order guides variable set and then redirect the user to the Order Guide to fill out the rest of the questions and submit. Any Ideas? thanks -
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2015 03:32 PM
thanks for all your help It set me in the right direction, the issue was you cannot query the journal of comments and work notes from a client side script - so what I was able to do was create a script include to pull all the incident info I needed.
For anyone who may need this info here is what I did:
Create a script include and specific fields your looking to return
My Script Include:
var getIncidentNotes = Class.create();
getIncidentNotes.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getIncidentNotes : function()
{
var scReq = new GlideRecord('incident');
scReq.addQuery('sys_id',this.getParameter('sysparm_incident_name'));
scReq.query();
if(scReq.next())
var fieldValue = "<b>Short Description:</b><br/>";
fieldValue += scReq.short_description + "<br/><br/>";
fieldValue += "<b>User Comments:</b>";
var answerc = '';
var notesc = scReq.comments.getJournalEntry(-1); //gets all journal entries as a string where each entry is delimited by '\n\n'
var nac = notesc.split("\n\n"); //stores each entry into an array of strings
for (var j = 0; j < nac.length; j++)
answerc = nac[j] + "<br/>" + "\n" + answerc;
fieldValue += answerc;
fieldValue += "<b>Work Notes:</b>";
var answer = '';
var notes = scReq.work_notes.getJournalEntry(-1); //gets all journal entries as a string where each entry is delimited by '\n\n'
var na = notes.split("\n\n"); //stores each entry into an array of strings
for (var i = 0; i < na.length; i++)
answer = na[i] + "<br/>" + "\n" + answer;
fieldValue += answer;
return fieldValue;
},
type: 'getIncidentNotes'
});
Next Created a Client Catalog Script to call the Script Include and Other Parameters from the UI Action (URL) :
function onLoad() {
//Populate the variables with the parameters passed in the URL
//Use the 'getParmVal' function below to get the parameter values from the URL
var callerid = getParmVal('caller_id');
var parentid = getParmVal('parent_request');
if(callerid){
g_form.setValue('caller_id',callerid);
}
if(parentid){
g_form.setValue('parent_request',parentid);
var worknotes = getNotes(parentid);
}
}
function getParmVal(name){
var url = document.URL.parseQuery();
if(url[name]){
return decodeURI(url[name]);
}
else{
return;
}
}
function getNotes(incidentid){
var ga = new GlideAjax('getIncidentNotes');
ga.addParam('sysparm_name','getIncidentNotes');
ga.addParam('sysparm_incident_name',incidentid);
ga.getXML(ParseXML);
}
function ParseXML(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
// alert(answer);
g_form.setValue('request_notes', answer);
}
Create UI Action to Add button to form
//Add notes and updates to the Incident
current.work_notes = "Ordered File Share Request - A Create FS Order";
current.state = '13'; //set to Awaiting Approval
current.update();
//Pass variables via URL to the Client Catalog Script
var newurl = "********/com.glideapp.servicecatalog_cat_item_guide_view.do?v=1&sysparm_initial=true&sysparm_guide=3c26ce281c040e0027b6490a570f6826&caller_id=" + current.u_affected_user + "&parent_request=" + current.sys_id + "";
action.setReturnURL(current);
action.setRedirectURL(newurl);
These Three Scripts were able to do the job!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2015 09:54 AM
Hi,
This can be done by passing the incident fields as URL parameters and using onload catalog client script on the Order guide form.
You should be able to get the order guide form url from the page properties and add the parameters to pass field values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2015 12:26 PM
OK thank you - I am able to get 2 of the 3 variables I need to pass via url but how would I pass work notes?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2015 06:45 AM
Hi,
If you want to copy the list of work notes then its truly a tedious task as you need to query the journal table to capture all the work notes for the record and then pass it as a url parameter. With Service Now when the URL length is more, it introduces the tiny_url which replaces all the URL parameters by capturing them in the Tiny URL table.
Navigating by URL - ServiceNow Wiki
Please refer the link.
Hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2015 03:32 PM
thanks for all your help It set me in the right direction, the issue was you cannot query the journal of comments and work notes from a client side script - so what I was able to do was create a script include to pull all the incident info I needed.
For anyone who may need this info here is what I did:
Create a script include and specific fields your looking to return
My Script Include:
var getIncidentNotes = Class.create();
getIncidentNotes.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getIncidentNotes : function()
{
var scReq = new GlideRecord('incident');
scReq.addQuery('sys_id',this.getParameter('sysparm_incident_name'));
scReq.query();
if(scReq.next())
var fieldValue = "<b>Short Description:</b><br/>";
fieldValue += scReq.short_description + "<br/><br/>";
fieldValue += "<b>User Comments:</b>";
var answerc = '';
var notesc = scReq.comments.getJournalEntry(-1); //gets all journal entries as a string where each entry is delimited by '\n\n'
var nac = notesc.split("\n\n"); //stores each entry into an array of strings
for (var j = 0; j < nac.length; j++)
answerc = nac[j] + "<br/>" + "\n" + answerc;
fieldValue += answerc;
fieldValue += "<b>Work Notes:</b>";
var answer = '';
var notes = scReq.work_notes.getJournalEntry(-1); //gets all journal entries as a string where each entry is delimited by '\n\n'
var na = notes.split("\n\n"); //stores each entry into an array of strings
for (var i = 0; i < na.length; i++)
answer = na[i] + "<br/>" + "\n" + answer;
fieldValue += answer;
return fieldValue;
},
type: 'getIncidentNotes'
});
Next Created a Client Catalog Script to call the Script Include and Other Parameters from the UI Action (URL) :
function onLoad() {
//Populate the variables with the parameters passed in the URL
//Use the 'getParmVal' function below to get the parameter values from the URL
var callerid = getParmVal('caller_id');
var parentid = getParmVal('parent_request');
if(callerid){
g_form.setValue('caller_id',callerid);
}
if(parentid){
g_form.setValue('parent_request',parentid);
var worknotes = getNotes(parentid);
}
}
function getParmVal(name){
var url = document.URL.parseQuery();
if(url[name]){
return decodeURI(url[name]);
}
else{
return;
}
}
function getNotes(incidentid){
var ga = new GlideAjax('getIncidentNotes');
ga.addParam('sysparm_name','getIncidentNotes');
ga.addParam('sysparm_incident_name',incidentid);
ga.getXML(ParseXML);
}
function ParseXML(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
// alert(answer);
g_form.setValue('request_notes', answer);
}
Create UI Action to Add button to form
//Add notes and updates to the Incident
current.work_notes = "Ordered File Share Request - A Create FS Order";
current.state = '13'; //set to Awaiting Approval
current.update();
//Pass variables via URL to the Client Catalog Script
var newurl = "********/com.glideapp.servicecatalog_cat_item_guide_view.do?v=1&sysparm_initial=true&sysparm_guide=3c26ce281c040e0027b6490a570f6826&caller_id=" + current.u_affected_user + "&parent_request=" + current.sys_id + "";
action.setReturnURL(current);
action.setRedirectURL(newurl);
These Three Scripts were able to do the job!