Notifications

6014 views

Description

In Service Portal, the Variable Editor widget fails when a catalog task is added to the portal. Also, variables do not display on the form.

Steps to Reproduce

  1. Navigate to Service Catalog > Open Records > Tasks.

  2. Open any catalog task that has variables.

    For more information, see Add catalog item variables to a task.

    Note that the variable formatter is displayed.

  3. Navigate to Service Portal > Pages.

  4. In the ID column, find and open the record for the index page.

  5. In Related Links, click Open in Designer.

  6. In the Widgets list on the left, select the Unordered List widget.

  7. Drag the widget and drop it in any location on the page.

  8. Click the edit icon to edit the widget. Use the following values:

    • Table: Catalog Task [sc_task]
    • Display field: Short description
    • Link to this page: Form
  9. Click Save.

  10. Navigate to Service Portal.

  11. Select the task from step 2.

    Note that the SP-Variable Editor widget fails and variables are not shown on the form. If you configure the form and remove the Variable editor, the error is not displayed.

Workaround

The fix to this problem is contained in Istanbul Patch 8 and onwards. In case an upgrade is not possible yet, use the following workaround.

  1. Clone the sp-variable-editor widget.
    For more information, see
    Create a widget.

  2. Replace the server script in the cloned widget with the script provided below. Please note the two different versions listed, before and after Istanbul P3a. Ref.: https://hi.service-now.com/kb_view.do?sysparm_article=KB0621849

  3. Modify the com_glideapp_servicecatalog_veditor sp_ui_formatter record to point to the cloned widget (nav_to.do?uri=sp_ui_formatter.do?sys_id=d71194730b012200b0b02c6317673a29).


- Server script to use in Istanbul before 3a -
(function() {
   data.table = $sp.getParameter("table") || options.table;
   data.sys_id = $sp.getParameter("sys_id") || $sp.getParameter("sl_sys_id") || options.sys_id;

   if (input) {
      var vars = [];
      var fields = input.sc_cat_item._fields;
      data.sys_id = input.sys_id;
      data.table = input.table;
      for (var v in fields) {
         vars.push(fields[v]);
         }
   
      if (data.table == "sc_cart_item")
      SPCart.updateItem(input.sys_id, vars);
      else
      $sp.saveVariables(input.table, input.sys_id, vars);
      }
   
   var gr = new GlideRecord(data.table);
   if (gr.get(data.sys_id)) {
      var recordClassName = gr.getRecordClassName();
      if (recordClassName != data.table) {
         data.table = recordClassName
         gr = new GlideRecord(data.table);
         gr.get(data.sys_id);
         }
      try {
         var catItem = data.table == "sc_task" ? gr.request_item.cat_item : gr.cat_item;
         data.sc_cat_item = $sp.getCatalogItem(catItem);
         var values = getValues(data.table, gr);
         
         for(var f in data.sc_cat_item._fields) {
         // Put the values into the cat item fields
            if (typeof values[f] != "undefined" && typeof values[f].value != "undefined") {
               data.sc_cat_item._fields[f].value = values[f].value;
               data.sc_cat_item._fields[f].displayValue = values[f].displayValue;
               data.sc_cat_item._fields[f].display_value_list = values[f].display_value_list;
               }
            }
         } catch (e) {
            console.log("Error loading the variable editor: " + e);
            }
         }
   
      function getValues(table, record) {
         var qs = new GlideappVariablePoolQuestionSet();
         if (table == "sc_cart_item")
         qs.setCartID(record.getUniqueValue());
         else if (table == "sc_task") {
            var taskID = record.getValue("delivery_task");
            if (taskID)
            qs.setTaskID(taskID);
            else
            qs.setTaskID(record.getUniqueValue());
         
            qs.setRequestID(record.request_item);
            } else
         qs.setRequestID(record.getUniqueValue());
      
         qs.load();
         var values = {};
         var questions = qs.getFlatQuestions().toArray();
      
         for (var i = 0; i < questions.length; i++) {
            var q = questions[i];
            var o = {value: q.getValue(), displayValue: q.getDisplayValue(), type: q.getType()
            };
         if (o.type == 21)
         o.display_value_list = q.getDisplayValues().toArray();
      
         values["IO:" + q.getId()] = o;
      }
   return values;
   }
})();

 

 

- Server script to use in Istanbul after 3a -
(function() {
   data.table = $sp.getParameter("table") || options.table;
   data.sys_id = $sp.getParameter("sys_id") || $sp.getParameter("sl_sys_id") || options.sys_id;

   if (input) {
      var vars = [];
      var fields = input.sc_cat_item._fields;
      data.sys_id = input.sys_id;
      data.table = input.table;
      for (var v in fields) {
         vars.push(fields[v]);
         }
   
      if (data.table == "sc_cart_item")
      SPCart.updateItem(input.sys_id, vars);
      else
      $sp.saveVariables(input.table, input.sys_id, vars);
      }
   
   var gr = new GlideRecord(data.table);
   if (gr.get(data.sys_id)) {
      var recordClassName = gr.getRecordClassName();
      if (recordClassName != data.table) {
         data.table = recordClassName
         gr = new GlideRecord(data.table);
         gr.get(data.sys_id);
         }
      try {
         var catItem = data.table == "sc_task" ? gr.request_item.cat_item : gr.cat_item;
         data.sc_cat_item = $sp.getCatalogItem(catItem,!!options.isOrdering, data.table);
         var values = getValues(data.table, gr);
         
         for(var f in data.sc_cat_item._fields) {
         // Put the values into the cat item fields
            if (typeof values[f] != "undefined" && typeof values[f].value != "undefined") {
               data.sc_cat_item._fields[f].value = values[f].value;
               data.sc_cat_item._fields[f].displayValue = values[f].displayValue;
               data.sc_cat_item._fields[f].display_value_list = values[f].display_value_list;
               }
            }
         } catch (e) {
            console.log("Error loading the variable editor: " + e);
            }
         }
   
      function getValues(table, record) {
         var qs = new GlideappVariablePoolQuestionSet();
         if (table == "sc_cart_item")
         qs.setCartID(record.getUniqueValue());
         else if (table == "sc_task") {
            var taskID = record.getValue("delivery_task");
            if (taskID)
            qs.setTaskID(taskID);
            else
            qs.setTaskID(record.getUniqueValue());
         
            qs.setRequestID(record.request_item);
            } else
         qs.setRequestID(record.getUniqueValue());
      
         qs.load();
         var values = {};
         var questions = qs.getFlatQuestions().toArray();
      
         for (var i = 0; i < questions.length; i++) {
            var q = questions[i];
            var o = {value: q.getValue(), displayValue: q.getDisplayValue(), type: q.getType()
            };
         if (o.type == 21)
         o.display_value_list = q.getDisplayValues().toArray();
      
         values["IO:" + q.getId()] = o;
      }
   return values;
   }
})();

 


Related Problem: PRB721238

Seen In

Helsinki Patch 4
Helsinki Patch 5
Helsinki Patch 7

Fixed In

Istanbul Patch 8
Jakarta Patch 2
Kingston

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2018-09-17 02:20:18
Published:2018-01-15