1302 views

Description

Using a Select Box variable filled by a Catalog Client Script appears as empty when accessing it from the RITM list. The list for the Select Box works as expected when opening the Catalog Item. After it is submitted, the RITM form incorrectlys shows the variable as empty. Even though the variable is stored in the sc_item_option_mtom table, the variable is not shown in the form and the list for the Select Box variable in the RITM form is empty / blank.

Steps to Reproduce

  1. Navigate to Service Catalog > Catalog Definitions > Maintain Items.
  2. Open a base system catalog item such as Acrobat or IPhone 6.
  3. Go to the Variables section or tab.
  4. Click New.
  5. Create a variable with the following settings:
    • Type: Select Box
    • Question: Select Box Variable
    • Name: select_box_variable
  6. Click Submit.
  7. Go to the Catalog Client Scripts section or tab.
  8. Click New.
  9. Create a catalog client script with the following settings to fill the new variable with all users from a department (for example, Development): 
    • Name: Fill new variable list
    • Applies to: A Catalog Item
    • Type: onLoad
    • Script:

      function onLoad() {
      var filter = '221f3db5c6112284009f4becd3039cc9';
      var gr = new GlideRecord('sys_user');
      gr.addQuery('department', filter);
      gr.query();
      while (gr.next()) {
      g_form.addOption('select_box_variable', gr.user_name, gr.user_name);
      }
      g_form.removeOption('select_box_variable', '');
      }

  10. Click Submit.
  11. In the catalog item record, right-click in the header bar and select Save
  12. Click Try It.
    Note that the new Select Box Variable is filled with the users from the catalog client script.
  13. Click Order Now.
  14. Under Description, click the item name to open the requested item record (RITM).
    Note that the select box variable appears as empty and blank. You should be able to see the user assigned to this variable / RITM. To confirm that the variable is filled, view the sc_item_option_mtom table.

Workaround

  1. Create a business rule:
    • Name: Business Selectbox Req
    • Table: Requested Item[sc_req_item]
    • Advanced: True
    • On the When to run tab:
      • When: display
      • Order: 100
    • On the Advanced tab, paste the following script:

      1. (function executeRule(current, previous /*null when async*/) {
      2.     var count=0;
      3.     var id = [];
      4.     var value = [];
      5.     var target = new GlideRecord('sc_item_option_mtom');
      6.     target.addQuery('request_item', current.sys_id);
      7.     target.addQuery('sc_item_option.item_option_new.type', 5);
      8.     target.query();
      9.     while(target.next()){
      10.         id[count] =  'ni.VE' + target.sc_item_option;
      11.         value[count] = target.sc_item_option.value.toString();
      12.         count++;
      13.      }
      14.      g_scratchpad.variable_id = id;
      15.      g_scratchpad.value = value;
      16.   })(current, previous); 

  2. Click Save.
  3. Create a client script.
    • Name: Client Selectbox Req
    • Table: Requested Item[sc_req_item]
    • Type: onLoad
    • Script:

      1.    function onLoad() {
      2.    var value = g_scratchpad.value;
      3.     var id = g_scratchpad.variable_id;
      4.     var count = id.length;
      5.         for(var i=0 ; i<count ; i++)
      6.             g_form.setValue(id[i],value[i]);
      7.                        
      8. }

  4. Click Submit.

Continue with the following steps for Table: Catalog Task[sc_task]. The steps below are similar to the steps above except for a minor change in the business rule script.

  1. Create a business rule:
    • Name: Business Selectbox Req
    • Table: Catalog Task[sc_task]
    • Advanced: True
    • On the When to run tab:
      • When: display
      • Order: 100
    • On the Advanced tab, paste the following script:

      1. (function executeRule(current, previous /*null when async*/) {
      2.     var count=0;
      3.     var id = [];
      4.     var value = [];
      5.     var target = new GlideRecord('sc_item_option_mtom');
      6.     target.addQuery('request_item', current.request_item.sys_id);
      7.     target.addQuery('sc_item_option.item_option_new.type', 5);
      8.     target.query();
      9.     while(target.next()){
      10.         id[count] =  'ni.VE' + target.sc_item_option;
      11.         value[count] = target.sc_item_option.value.toString();
      12.         count++;
      13.      }
      14.      g_scratchpad.variable_id = id;
      15.      g_scratchpad.value = value;
      16.   })(current, previous); 


  2. Click Save.
  3. Create a client script.
    • Name: Client Selectbox Req
    • Table: Catalog Task[sc_task]
    • Type: onLoad
    • Script:

      1.    function onLoad() {
      2.    var value = g_scratchpad.value;
      3.     var id = g_scratchpad.variable_id;
      4.     var count = id.length;
      5.         for(var i=0 ; i<count ; i++)
      6.             g_form.setValue(id[i],value[i]);
      7.                        
      8. }

  4. Click Submit.

Related Problem: PRB679673

Seen In

Fuji Patch 13 Hot Fix 1
Geneva Patch 4 Hot Fix 2
Geneva Patch 6
Helsinki Patch 0 Hot Fix 1
Helsinki Patch 0 Hot Fix 3
Helsinki Patch 1
Helsinki Patch 2
Helsinki Patch 2 Hot Fix 2
Helsinki Patch 3

Fixed In

Helsinki Patch 4
Istanbul

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2017-06-06 20:19:18
Published:2016-09-09