60 views

Description

When executing a REST Service Catalog API, the variables are retrieving:
{  "8": "sys_user", }

instead of:
{  "User": "sys_user", }

Steps to Reproduce

  1. Go to REST API Explorer
    2. Set Namespace = sn_sc , API Name = Service Catalog API , API Version = latest
    3. Choose Specific Catalog Item (GET)
    4. Use this sys_id = c0c5b2db4fbf4200086eeed18110c718
    5. Press "Send" (Run the GET)

    Steps to reproduce

    and observe the Response shows:
    **********
    "variables": [
    {
    "label": "it_to_it",
    "type": 0,
    "mandatory": false,
    "displayvalue": null,
    "friendly_type": "container_start",
    "render_label": false,
    "read_only": false,
    "children": [
    {
    "8": "sys_user",
    **********
    =========>
    ****
    Expected:
    { "User": "sys_user", }
    Actual:
    { "8": "sys_user", }
    ****

Result

Workaround

This problem was fixed in Kingston.

On previous releases, the "8" item from the Service Catalog API response should be ignored.

The advanced workaround listed below can be adopted. Please contact SN support if assistance is needed.

1. Open this Script Include "RestCatalogUtil"
/nav_to.do?uri=sys_script_include.do?sys_id=0ae1e780c3001200d68d3b0ac3d3ae4e

2. Switch to the "Service Catalog REST API" application context

3. Add these lines in the script "RestCatalogUtil" and save

   // Test for PRB1065653 adding following lines
    _processReferenceLabel: function(variable) {
        var value = variable['8'];
        delete variable['8'];
        variable['reference'] = value;
    },

    _processColumnsList: function(columns) {
        for (var column = 0; column < columns.length; column++) {
            var columnData = columns[column];
            columns[column] = this._processColumn(columnData);
        }
        return columns;
    },

    _processColumn: function(colData) {
        if (colData['11'] != undefined) {
            var colLabel = colData['11'];
            delete colData['11'];
            colData.label = colLabel;
        }
        if (colData['8'] != undefined) {
            var refLabel = colData['8'];
            delete colData['8'];
            colData.referenceTable = refLabel;
        }

        if (colData['choices'] != undefined) {
            for (var ch = 0; ch < colData['choices'].length; ch++) {
                this._processChoice(colData.choices[ch]);
            }
        }
        return colData;
    },

    _processChoice: function(choice) {
        var choiceLabel = choice['11'];
        delete choice['11'];
        choice.label = choiceLabel;
    },

    _processContainerVariables: function(variable) {
        if (variable.children) {
            variable.children = this.processVariables(variable.children);
        }
    },
    processVariables: function(vars) {
        var variables_array = [];
        for (var var_index = 0; var_index < vars.length; var_index++) {
            var variable = vars[var_index];
            var type = variable.type;
            // refernce variable, lookup select box and lookup multiple choice
            if (type == 8 || type == 22 || type == 18) {
                this._processReferenceLabel(variable);
            } else if (type == 21) {
                variable.columns = this._processColumnsList(variable.columns);
            } else if (type == 0) {
                this._processContainerVariables(variable);
            }
            variables_array.push(variable);
        }
        return variables_array;
    },
    
// Test for PRB1065653 adding following lines ends here


4. Open "Specific Catalog Item"

/nav_to.do?uri=sys_ws_operation.do?sys_id=8f017f03c3330200d68d3b0ac3d3ae18

5. Switch to the "Service Catalog REST API" application context

6. Comment/Add these lines below and Save: 

// Changings based on PRB1065653 instructions, line below replaced by two subsequents lines
//itemDetails.variables = catItem.getVariables(false);
var unprocessed_variables = catItem.getVariables(false);
itemDetails.variables = new RestCatalogUtil().processVariables(unprocessed_variables);
// Changings end here PRB1065653


7. In order to validate, open a new tab in the browser and check if the URL below opens and renders correctly:

<instance>.service-now.com/api/sn_sc/servicecatalog/items/c0c5b2db4fbf4200086eeed18110c718

 


Related Problem: PRB1065653

Seen In

There is no data to report.

Fixed In

Kingston

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2018-02-23 06:43:43
Published:2018-02-23