Generate value for drop down menu in UI builder

vidhya_mouli
Giga Sage

I have a data resource:@data.get_developer_names.results

which returns the following values:

[
  {
    "_row_data": {
      "displayValue": "Marcelo Arostegui",
      "uniqueValue": "4782abf03710200044e0bfc8bcbe5d40"
    },
    "name": {
      "value": "Marcelo Arostegui",
      "displayValue": "Marcelo Arostegui"
    }
  },
  {
    "_row_data": {
      "displayValue": "Ezekiel Mildon",
      "uniqueValue": "56826bf03710200044e0bfc8bcbe5daf"
    },
    "name": {
      "value": "Ezekiel Mildon",
      "displayValue": "Ezekiel Mildon"
    }
  },
  {
    "_row_data": {
      "displayValue": "Roman Simone",
      "uniqueValue": "f6826bf03710200044e0bfc8bcbe5dfd"
    },
    "name": {
      "value": "Roman Simone",
      "displayValue": "Roman Simone"
    }
  },
  {
    "_row_data": {
      "displayValue": "Judy Gartenmayer",
      "uniqueValue": "5a826bf03710200044e0bfc8bcbe5dc3"
    },
    "name": {
      "value": "Judy Gartenmayer",
      "displayValue": "Judy Gartenmayer"
    }
  },
  {
    "_row_data": {
      "displayValue": "Rich Gleave",
      "uniqueValue": "32826bf03710200044e0bfc8bcbe5dfe"
    },
    "name": {
      "value": "Rich Gleave",
      "displayValue": "Rich Gleave"
    }
  },
  {
    "_row_data": {
      "displayValue": "Valerie Pou",
      "uniqueValue": "0e826bf03710200044e0bfc8bcbe5d6a"
    },
    "name": {
      "value": "Valerie Pou",
      "displayValue": "Valerie Pou"
    }
  },
  {
    "_row_data": {
      "displayValue": "Jess Assad",
      "uniqueValue": "06826bf03710200044e0bfc8bcbe5d41"
    },
    "name": {
      "value": "Jess Assad",
      "displayValue": "Jess Assad"
    }
  },
  {
    "_row_data": {
      "displayValue": "Megan Burke",
      "uniqueValue": "46cd276ba9fe19810024aa59b51d6ef7"
    },
    "name": {
      "value": "Megan Burke",
      "displayValue": "Megan Burke"
    }
  },
  {
    "_row_data": {
      "displayValue": "Denise Speegle",
      "uniqueValue": "42826bf03710200044e0bfc8bcbe5d96"
    },
    "name": {
      "value": "Denise Speegle",
      "displayValue": "Denise Speegle"
    }
  },
  {
    "_row_data": {
      "displayValue": "Don Mestler",
      "uniqueValue": "3682abf03710200044e0bfc8bcbe5d0e"
    },
    "name": {
      "value": "Don Mestler",
      "displayValue": "Don Mestler"
    }
  },
  {
    "_row_data": {
      "displayValue": "Maurine Monroy",
      "uniqueValue": "1e826bf03710200044e0bfc8bcbe5dc0"
    },
    "name": {
      "value": "Maurine Monroy",
      "displayValue": "Maurine Monroy"
    }
  }
]

 

I have a drop-down with the following script on List item:

 

 

function evaluateProperty({
    api,
    helpers
}) {

    function evaluateProperty({
        api,
        helpers
    }) {
    var jsonObj = api.data.get_developer_names.results;
    console.log("\n\nSV: " + JSON.stringify(jsonObj));
    var numOfDev = jsonObj.length;
    console.log("\n\nSV: " + numOfDev);
    var jsonVar = "[";
    for (var i = 0; i < numOfDev; i++) {
        jsonVar = jsonVar + '{"id":"' +
            jsonObj.i._row_data.uniqueValue +
            '","label":"' +
            jsonObj.i._row_data.displayValue +
            '"}';

        if (i < (numOfDev - 1)) {
            jsonVar = jsonVar + ",";
            console.log("\n\nSV: " + jsonVar);
        }
    }
    jsonVar = jsonVar + ']';
    
    return jsonVar;
    


}

 

However in the console I see no value for jsonObj and the length is 0. Any suggestion why so?

1 ACCEPTED SOLUTION

vidhya_mouli
Giga Sage

I resolved this. It was an ACL issue. The user did not have read permission.

View solution in original post

2 REPLIES 2

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I wonder if you're running into race conditions where the component is rendering before the data is returned. I'd add a JSON type client state parameter here. You can use this code in a client script to set the client state parameter and then bind the client state parameter to the drop-down. This also gives you more flexibility in changing the values in the dropdown.

vidhya_mouli
Giga Sage

I resolved this. It was an ACL issue. The user did not have read permission.