Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

When a service offering and category combination results in a category which has an attached catalog item, the user will be prompted to use that item instead of creating an incident or generic request.  The user won't be able to save an incident record with a category that has been identified as being satisfied as a catalog item.  At a high level:

  • The client script fires and opens a dialog when there's an available catalog item
  • The client script opens a dialog with its contents specified by the ui page
  • If the user accepts that the ticket will be converted, a ui action will fire, which updates the ticket if it was saved and redirects the user to the catalog item with as much information pre-populated as possible.
  • If the user doesn't accept that the ticket will be converted, the category is cleared and the user must select again.

Client Script

Client script fires when category changes

Needs to only fire when there's an available catalog item.

Code Block
languagejs
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue == '') {
		return;
	}
	
	//Type appropriate comment here, and begin script below
	conversionDialog();
	
	function conversionDialog() {
		//Get the values to pass into the dialog
		var requester = g_form.getReference('u_requester');
		
		var gr = new GlideRecord('sc_cat_item');
		if (gr.get(g_form.getReference('u_category').u_catalog_item)) {
			var item = gr.name;
		}
		
		//Initialize and open the dialog
		var dialog = new GlideDialogWindow("conversion_dialog"); //Instantiate the dialog containing the UI Page 'add_commentsconversion_dialog'
		dialog.setTitle("Ticket Conversion"); //Set the dialog title
		
		dialog.setPreference("catalog_item", item); //Pass the item name to the dialog
		dialog.render(); //Open the dialog
	}
}

 

Ui Page

Ui Page which shows the dialog

...

Code Block
languagexml
<g:ui_form>
  <!-- Get the values from dialog preferences -->
<g:evaluate var="jvar_catalog_item"
    expression="RP.getWindowProperties().get('catalog_item')" />
<g:evaluate var="jvar_cuser"
    expression="RP.getWindowProperties().get('cuser')" />
<g:evaluate var="jvar_cuser_name"     expression="RP.getWindowProperties().get('cuser_name')" />
   <!-- Set up form fields and labels -->
<style>
#popup_close_image
{
display:none;
}
</style>   
<table width="100%">
     <tr id="description_row" valign="top">
        <td colspan="2">
           <!-- Short description value used as a label -->
           A catalog item is available for this service offering and category combination.  This ticket will be converted to the available catalog item '${jvar_catalog_item}'.
        </td>
     </tr>
     <tr>
       <td colspan="2">
<!-- Requester : <g:ui_reference name="cuser" id="cuser" table="sys_user" value="${jvar_cuser}" displayvalue="${jvar_cuser_name}"/>
-->        </td>
     </tr>
     <tr id="dialog_buttons">
        <td colspan="2" align="right">
           <!-- Add OK/Cancel buttons. Clicking OK calls the validateComments script -->
           <g:dialog_buttons_ok_cancel ok="gsftSubmit(null, g_form.getFormElement(), 'convert_incident');" ok_type="button" cancel_type="button" cancel="g_form.setValue('u_category',false);GlideDialogWindow.get().destroy();" />
        </td>
     </tr>
  </table>
</g:ui_form>

 

UI Action

Catalog item sys_id is hardcoded right now, but it'll be read from the current records category info.

Need to resolve the ticket if it was committed.

Code Block
languagejs
var url = "com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=6c80d6f66f323100fc62abcf9f3ee49f&sysparm_description=" + current.description + "&sysparm_short_description=" + current.short_description;
action.setRedirectURL(url);