HP Service Manager Service Catalog User Selections
May 3, 2010
Service Catalog User Selections: Placing them into Actual Fields
In Service Manager, have you ever run into a need to make your “User Selections” on your Service Catalog Items actually useable? The article content below will lay out an overview of Service Catalog Item “User Selections” and how you can use Javascript to make good use out these user selections.
“User Selections” on the Service Catalog Item. What are they? Simply put, in Service Manager, if you use the Service Catalog to allow your end users to request certain items, they have the ability to fill out a small set of fields that will contain information concerning the Service Catalog Item they are requesting. These fields that contain this user driven information are known as the Service Catalog’s “User Selections.”
So what? What do these “User Selections” have to do with me and my Service Manager System you might ask? Well, we as Service Manager programmers have the ability to code our Service Catalog Items to easily open Request records (of specific Request Categories) in order to procure these Service Catalog Item Requests made by our end users. So, simply speaking, we can open Request Tickets for our end user Service Catalog Item Requests that will carry the info they provide to us in these “User Selections.”
Now for the fun part! If you have used Service Catalog before, then you already know the ease with which you can setup these Service Catalog Items and make them available to your end users for requesting. However, with this ease comes a few issues. Sure, we can setup our “User Selections” for these Service Catalog items with ease, but with this comes the sheer fact that you cannot report on these “User Selections,” you cannot kick these “Users Selections” back to your infrastructure support teams on emails, and generally, these “User Selections” will exist in a virtual vacuum of sorts in that they are confined to the Request record (or whatever record you are using to procure your service catalog requests) in which they reside.
Well, there is a solution to this problem! With the use of Javascript we can take any of these fields from the “User Selections” and place them into actual fields on the record you are using to procure your Service Catalog Item requests. See the technical section below for information on how to do this inside of Service Manager.
Now for the technical part:
If, for example, you are using Request (ocmq) records to procure your Service Catalog Item Requests, you already know that the “User Selections” are all held in one field on the Request (ocmq) record named “svc.options.” This field holds these “User Selections” in an xml based format so that, when placed inside the context of a dynamic form on the request record, the user selections can be properly displayed to the user viewing the record. That’s nice, however, this does not allow us to have access to those “User Selections” for reporting, email reporting etc. (unless you want to kick back the nasty svc.options field to your users on reports and emails! But nobody wants to do that!).
So, below is an example of a block of Javascript that can be used to go into any part of this “svc.options” field to grab out a field value and place that value into any existing field on the ocmq record. Please note, for this specific example, that the content in the svc.options field on the actual ocmq record is as follows (and also note that this is a real life example of the svc.options field belonging to an ocmq record that was opened from a Service Catalog Item Request that held “User Selections”. Those “User Selections,” in this example, are held in the svc.options field inside of the ocmq record seen below):
>d svc.options in $L.file
<form><text id="vwdateneeded" label="Date and Time of Termination :*">4-4-09 1:30 PM</text><select id="vwpriority" label="Priority :*" style="combo">Emergency<option label="" /><option id="0" label="Standard">Standard</option><option id="1" label="Emergency">Emergency</option></select><select id="vwemployeetype" label="Employee Type :*" style="combo">Permanent<option label="" /><option id="0" label="Permanent">Permanent</option><option id="1" label="Temporary">Temporary</option><option id="2" label="Consultant">Consultant</option></select><text id="vwreportsto" label="Reports To :*">Test Manager</text><select id="vwtypeoftetermination" label="Type of Termination :*" style="combo">VCI Termination<option label="" /><option id="0" label="VCI Termination">VCI Termination</option><option id="1" label="Transfer Out Of VCI Domain">Transfer Out Of VCI Domain</option></select><text id="vwmycomments" label="Comments *:" multiline="true">This is a Test 
This is a Test
This is a Test</text></form>
***Editorial note – the line above needs to stay formatted as displayed for this to work correctly. Unfortunately the line above does not wrap and is displayed under part of the content bars on the right. If you would like to receive the full code for this particular item please email lwalker@stratacominc.com.
As you can see, this is an ugly field value to say the least! So, the below javascript is an example of how we can pull out a value in one of these “User Selections” and place it into an actual field on the ocmq record (and then we will have access to report on this field and kick it back to our users in emails as well!). Please note that you would place this block of Javascript below into the next available Javascript box in the actual Javascript section of the “ocmq” format control (Add and Update Conditions for this specific example are: category in $file=”sarterm”). This means that when an ocmq record is opened or updated and has a value of “sarterm” in the actual “category” field, this Javascript will fire on add and update. Again, this is just for our example here, but this Javascript can be applied (with modification of course to point to the right area in the svc.options field) to any instance where a User Selection must be dragged out and placed into a field on the record. Now for the script:
//Begin Script
//Grab the current ocmq File
var file = system.vars.$file;
//Grab the svc.options field out of the ocmq record
var holdSvcOptions = file.svc_options;
//Use Basic String Functions in Javascript to Grab out the String for
//the vwreportsto field user selection.
var positionofManager = holdSvcOptions.indexOf('vwreportsto');
var grabManagerCutUp = holdSvcOptions.substring(positionofManager);
var grabManGreaterThanSymbolPos = grabManagerCutUp.indexOf('>');
var grabManCutUpFurther = grabManagerCutUp.substring(grabManGreaterThanSymbolPos);
var grabManLessThanSymbolPos = grabManCutUpFurther.indexOf('<');
var myManager = grabManCutUpFurther.substring(1,grabManLessThanSymbolPos);
//Place that String into our actual manager field on the ocmq record
file.manager = myManager;
//End Script
In Summary, you can see above that we are keying off of the value that is in the “vwreportsto” “User Selection” (inside of the svc.options field on the ocmq record) and we are dragging that value out (via basic string manipulation functions in Javascript) and placing that value into the actual “manager” field on the ocmq record (the last line in the javascript does this). So this means, for our example, that when our end user goes and requests a Service Catalog Item that opens a Request (ocmq) record of category “sarterm”, this block of code will fire on Add and Update to pull the correct “User Selection” out and place it into an actual field on the ocmq record.
***Now, what if we want to drag out the contents of a multi text field from our User Selections and place that into an array field on our ocmq record? Below is a Block of Code that will extract the contents of a multi text User Selection from the same “svc.options” field shown above and place that into an array field on the ocmq record. Please again note that you would place this block of Javascript below into the next available Javascript box in the actual Javascript section of the ocmq format control (Add and Update Conditions for this example are: category in $file=”sarterm”). Please also note that the section of that svc.options field (from above) we will be referring to in this block of Javascript code is:
…></select><text id="vwmycomments" label="Comments *:" multiline="true">This is a Test 
This is a Test
This is a Test</text></form>
And now the Javascript is below. Again, the Javascript will pull out the multi text user selection field value (for the field named “vwmycomments”) and place that value into an array field named “description” on the actual ocmq record. Note the use of the Javascript based “split()” function as this takes the contents of the multi text user selection and packages it into a useable array that can then be placed into the “description” field on the ocmq record:
//Begin Script
//Grab the current ocmq File
var file = system.vars.$file;
//Grab the svc.options field out of the ocmq record
var holdSvcOptions = file.svc_options;
//Use Basic String Functions in Javascript to Grab out the Value for
//the multitext vwmycomments field user selection.
var positionofDesc = holdSvcOptions.indexOf('vwmycomments');
var grabDescCutUp = holdSvcOptions.substring(positionofDesc);
var grabDescGreaterThanSymbolPos = grabDescCutUp.indexOf('>');
var grabDescCutUpFurther = grabDescCutUp.substring(grabDescGreaterThanSymbolPos);
var grabDescLessThanSymbolPos = grabDescCutUpFurther.indexOf('<');
var myDesc = grabDescCutUpFurther.substring(1,grabDescLessThanSymbolPos);
//Take the multi text value you just grabbed and package it into an //array
var x = myDesc.split("
");
//Place that array into the description field on the ocmq record.
file.description = x;
//End Script
Please again note that, for this example, if an End User Selects a Service Catalog Item that fires a Request (ocmq) record of category “sarterm” then this block of code will fire and the contents of the User Selection we choose in this code (in this case it’s the contents of the user selection named “vwmycomments”) will be placed in the actual ocmq field we choose as well (in this case we place this info into the “description” field on the ocmq record).
How are these two blocks of Javascript code from above helpful? The answer is simple in that we are able to extract the “User Selections” we choose form the “svc.options” field and place these values into actual fields on the ocmq record (or whatever record you are using to procure you Service Catalog Item Requests). This allows us to then report on these fields, kick these fields back to users on emails, and generally have full availability to these fields at all times.
Comments
Got something to say?