Using widgets in catalog items and displaying info from a record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 07:32 AM
Hello Everyone
I'm working on building a simple widget I can use in a catalog item to display information from a software model record. I've put together something that works, but seems highly inefficient. Is it possible to use a widget client script to get a value from a catalog item and to then query a CMDB record?
Background: We have a catalog item where people can request software, which has a lookup list that references records in our Software Model table (cmdb_software_product_model). We want to have a way to display "more detail/special instructions" about individual models. I added an HTML field to our Software Model table called Special Instructions where our Asset Manager can create shorts notes about the product. If a requester selects a software product that has Special Instructions, then I want those instructions to display on the catalog item.
Using this article as a guide Embedding widgets in Service Catalog - ServicePortal.io - Service Portal, CMS, and Custom Apps I created a multi-line text variable in my catalog item to store the contents of any instructions from the selected model. I use a catalog client script to query the selected software model and set a value in my catalog variable.
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
if (newValue != ''){
var jp = new GlideRecord('cmdb_software_product_model');
jp.addQuery('sys_id', newValue);
jp.query(doAlert);
}
}
function doAlert(jp){
while (jp.next()){
g_form.setValue('si', jp.u_special_instructions);
}
}
Next I created a widget that gets the value from my catalog variable and pushes the HTML into the HTML Template.
Finally, I have a Macro variable on my catalog item that uses the new widget. All of this works, but I'm looking for a better way to complete the query and display my results.
Thank you!
Rick Mann