Access to request.requested_for from catalog task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2014 07:19 PM
I am trying to access the value for requested_for on the request associated to a catalog task.
I have a catalog task and need to find the value for the requested_for field at the request level. I am doing this so that if there is a requested_for value then I can use that value to filter the list of available computers to only the computers that are assigned to the user specified in the requested_for field. I am doing this using a function I created for the reference qualified on cmdb_ci.
However, no matter what way I try to reference the request, I cannot get to that value (a value always exists).
I have tried things like the following:
current.requested_item.request.requested_for
parent.request.requested_for
current.request.requested_for
and several others....
Does anyone know of a way this is possible? Your help is greatly appreciated!
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2014 07:43 PM
Hey Joel,
Can you please post your entire script include in here? current.request.requested_for should be pulling the correct value.
Thanks,
Mitch Stutler
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2014 09:45 PM
My apologies about the wait. I wanted to make sure I clean up the script and put in comments:
Code |
---|
function getCMDBCIsForIncident() { var answer = "sys_class_name=*"; var thisCategory = ""; var targetEmployee = ""; var thisSubcategory = ""; //Find targetEmployee for use in filtering for the requestor if (current.caller_id){ //for use on incidents targetEmployee = current.caller_id; } else if (current.requested_for) { //for use in requested items targetEmployee = current.requested_for; } else if (current.request.requested_for) { //for use in catalog tasks targetEmployee = current.request.requested_for; } //Find the appropriate category field if (current.category) { //used from Incident Form thisCategory = current.category.toString(); } else if (current.variables.category) { //used from incident record producer thisCategory = current.variables.category.toString(); } //set answser for reference qualifier based on category switch (thisCategory) { case "software": answer="sys_class_name=cmdb_ci_service"; //business services break; case "hardware": answer="sys_class_nameINSTANCEOFcmdb_ci_server"; //servers break; case "network" : answer="sys_class_nameINSTANCEOFcmdb_ci_netgear"; //network gear break; default: answer = "sys_class_name=*"; //if not specified - return all CIs } //Find the appropriate subcategory field if (current.subcategory) { //incident form subcategory thisSubcategory = current.subcategory.toString(); } else if (current.variables.subcategory) { //incident record producer subcategory thisSubcategory = current.variables.subcategory.toString(); } else if (current.variables.u_subcategory) { //request item form subcategory thisSubcategory = current.variables.u_subcategory.toString(); } else if (current.u_subcategory) { // requested_item form subcategory thisSubcategory = current.u_subcategory.toString(); } else if (current.requested_item.u_subcategory) { //catalog item subcategory thisSubcategory = current.requested_item.u_subcategory.toString(); } //If the subcategory is set to computer, return only the computers that are assigned to the requestor switch (thisSubcategory) { case "Computer": answer="sys_class_name=cmdb_ci_computer^assigned_to=" + targetEmployee; break; } return answer; } |
This is also applied to an incident on the cmdb_ci as a reference qualifier. This works perfectly there. If the subcategory is 'computer', allowed cmdb_ci's are set to only the computers that are assigned to the caller_id.
When I use this on the requested item or catalog task, it returns no result. I believe this is because it is not finding a requested_for value.
Any help is greatly appreciated.
FYI - I have a category/subcategory set of fields added to requested item. They are u_category and u_subcategory respectfully. They are dependent variables just like in the incident form. For the catalog task form, I have added the category/subcategory from the requested item to the catalog task form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2014 10:40 PM
else if (current.requested_for) { //for use in requested items
targetEmployee = current.requested_for;
}
else if (current.request.requested_for) { //for use in catalog tasks
targetEmployee = current.request.requested_for;
}
The first line is not correct , for the requested item it should say, "current.request.requsted_for", as the requested_for field is not on the requested_item table, it is coming from the request table, and thus we can get the value of requested_for only by referring to the request table.
The code is fine for the catalog task.
But if it does not work, just try to fetch the requested_for using a glide record on the request table.
var req=new GliedRecord('request')
req.addQuery('sys_id',current.request);
req.query();
if(req.next())
{
var requestedfor=req.requested_for;
}
requestedfor will contain the desired value.
Regards
Pratul Agarwal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2014 11:03 PM
Hi Joel,
In the requestd item (sc_req_item) table , the requested for dot walking is current.request.requested_for.
In catalog task (sc_task) table, the requested for is current.request_item.request.requested_for