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 11:30 PM
Hi Joel,
If above script is written in a Script Include, you need to pass a reference of the catalog task to the function. Then you can access the fields using that reference.
function getCMDBCIsForIncident(scTask) {
//and your code will be like
if (scTask.subcategory) { //incident form subcategory
thisSubcategory = scTask.subcategory.toString();
}
}
you can pass current as a parameter to your function call.
Thanks,
Mandar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2014 06:28 AM
It appears that I had a few issues but the most prominent was that I was referring to request_item as requested_item.
Here is the final code that seemed to work for me.
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.request_item.request.requested_for) { //for use in catalog tasks targetEmployee = current.request_item.request.requested_for; } else if (current.request.requested_for) { //for use in catalog tasks and requested Items targetEmployee = current.request.requested_for; } else if (current.variables.requested_for) { //for use in catalog request form targetEmployee = current.variables.requested_for; } else { targetEmployee = gs.getUserID(); } //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(); } else if (current.variables.u_category) { //used from request item catalog form thisCategory = current.variables.u_category.toString(); } else if (current.u_category) { //used from incident record producer thisCategory = current.u_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.request_item.u_subcategory) { //catalog item subcategory thisSubcategory = current.request_item.u_subcategory.toString(); } else if (current.u_subcategory) { // requested_item form subcategory thisSubcategory = current.u_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(); } //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; } |
Thanks everyone!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2014 09:30 PM
Hey Joel,
If you are using current.request.requested_for or current.requested_item.request.requested_for you are basically using dot walking, and you should get the desired output.
If not you can just glide through the "request" table and filter out the specific record using the "Request" field in your catalog task form, and then you can retrieve the "requested_for" value.
If you could provide the entire script ?
Regards
Pratul Agarwal