Notifications

5727 views

Description

Catalog Client scripts on order guides do not work in Service Portal since Jakarta Patch 9. There is no issue in back-office Native UI, when clicking on 'Try It' on the order guide.

 

Steps to Reproduce

 

  1. Log in to a Jakarta Patch 9 instance.

  2. Open the order guide:
     /sp?id=sc_cat_item_guide&sys_id=25110912372211003e7d40ed9dbe5dd6

  3. Observe there is a catalog client script that is written for this order guide:
     /catalog_script_client.do?sys_id=407a93f8dbead700e99236cb7c9619e7

  4. Observe catalog client scripts are not executed.

  5. Observe the issue does not occur in native UI:
     /com.glideapp.servicecatalog_cat_item_guide_view.do?v=1&sysparm_initial=true&sysparm_guide=25110912372211003e7d40ed9dbe5dd6

  6. The issue occurs on order guides in service portal: /sp?id=sc_cat_item_guide&sys_id=25110912372211003e7d40ed9dbe5dd6

  7. Observe the issue is not seen for any client script on catalog items, record producers, and normal forms in service portal:
    • record producer on service portal: /sp?id=sc_cat_item&sys_id=eb0d5b18dbd21300e99236cb7c96194b
    • incident form in service portal: /sp?id=form&table=incident&sys_id=8d641046c0a80164000bc7c0d3ed46a0

Workaround

This issue is fixed in all currently supported versions. Please review the Fixed In section to determine the latest available patch your instance can be upgraded to.

In case an upgrade is not possible yet, the workaround below can be temporarily implemented. This will need to be tested and verified in a sub-production instance before being pushed into production. The workaround will also need to be removed after upgrading to JP10 or KP7. 

  1. If you have a cloned widget already proceed to step 2, else clone the Order Guide widget sp_config?id=widget_editor&sys_id=4d062372ff130200ba13ffffffffffc4
  2. In the server script section, after the following line
        data.sc_cat_item = $sp.getCatalogItem(data.sys_id, true);
    Add the following workaround:
    1. Fetch all variable sets for Catalog item
    2. Fetch all client scripts on Variable sets
    3. Push all client scripts.
// Workaround: - PRB1287069
var onChangeCount = data.sc_cat_item.client_script.onChange.length,
onSubmitCount = data.sc_cat_item.client_script.onSubmit.length,
onLoadCount = data.sc_cat_item.client_script.onLoad.length;
// TODO, hot fix should self-de-activate when SN fixes bug
if (onChangeCount === 0 && onSubmitCount === 0 && onLoadCount === 0) {
  // it's unlikely that we didn't have any client scripts, let's see if there's a bug
  // and add them back manually if so
  // get all catalog client scripts for this cat item
  var grClientScripts = new GlideRecord('catalog_script_client');
  grClientScripts.addQuery('cat_item', data.sys_id);
  grClientScripts.query();
  while (grClientScripts.next()) {
    //console.log('found script: ' + grClientScripts.name);
    var clientScriptType = grClientScripts.type.toString();
    // TODO: skip adding client scripts if already added (by SN platform)
    // add the missing scripts manually
     data.sc_cat_item.client_script[clientScriptType].push({
      fieldName: getFieldName(grClientScripts.cat_variable.toString()),
      name: grClientScripts.name.toString(),
      script: grClientScripts.script.toString(),
      sys_id: grClientScripts.sys_id.toString(),
      tableName: ""
    });
  }
 
  // Start workaround for Variable sets
  var grVariableSets = new GlideRecord('io_set_item');
  grVariableSets.addQuery('sc_cat_item', data.sys_id);
  grVariableSets.query();
 
  while (grVariableSets.next()) {
    var variableSetSysId = grVariableSets.variable_set.toString();
    //console.log("Variable Set Sys ID:- "+variableSetSysId);
    var grClientScriptsVarSet = new GlideRecord('catalog_script_client');
    grClientScriptsVarSet.addQuery('variable_set', variableSetSysId);
    grClientScriptsVarSet.query();
 
    while (grClientScriptsVarSet.next()) {
      //console.log('found script: ' + grClientScripts.name);
      var clientScriptType = grClientScriptsVarSet.type.toString();
      // TODO: skip adding client scripts if already added (by SN platform)
      // add the missing scripts manually
      data.sc_cat_item.client_script[clientScriptType].push({
        fieldName: getFieldName(grClientScriptsVarSet.cat_variable.toString()),
        name: grClientScriptsVarSet.name.toString(),
        script: grClientScriptsVarSet.script.toString(),
        sys_id: grClientScriptsVarSet.sys_id.toString(),
        tableName: ""
      });
    }
  }
  // End workaround for variable sets
}
 
function getFieldName(ioName) {
  return data.sc_cat_item._fields[ioName].variable_name;
}
// End workaround
 

Related Problem: PRB1287069

Seen In

Jakarta Patch 9

Fixed In

Jakarta Patch 10
Jakarta Patch 9 Hot Fix 4
Kingston Patch 6 Hot fix 5
Kingston Patch 7
London

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2018-12-05 08:33:51
Published:2018-10-17