This topic contains 0 replies, has 0 voices, and was last updated by jmacdonald 7 years, 3 months ago.

  • Author
    Posts
  • #18222

    jmacdonald

    Hello all,

    I’ve been trying to use .getSelectOptions on a custom select field in a SS2.0 client script, the method always seems to return an empty array so I decided to have a look at the code behind the method.

    Code:
    /**
    * Returns a list of available options on a select field. This API can be used on both standard and custom select fields. Only the first 1,000 available options will be returned by this API. Does nothing if this field is not a select/multiselect
    * @param {string} [filter] Will not filter if not present.
    * @param {string} [filteroperator] Supported operators are contains | is | startswith. If not specified, defaults to the contains operator.
    * @return {Array}
    *
    */
    function getSelectOptions(filter, filteroperator)
    {
    var sOptions = [];
    var uiField = fieldObj.getUIField();
    var dropdown = (fieldObj.getType() === “select”) ? getDropdown(uiField) : getMultiDropdown(uiField);
    if (dropdown)
    {
    var optionValues = dropdown.valueArray;
    var optionTexts = dropdown.textArray;
    var filterfunction = null;
    if (!!filter)
    {
    filteroperator = filteroperator || “contains”;
    if (filteroperator === “is”)
    {
    filterfunction = function (v) { return v === filter; };
    }
    else if (filteroperator === “startswith”)
    {
    filterfunction = function (v) { return (“” + v).indexOf(filter) === 0; }
    }
    else if (filteroperator === “contains”)
    {
    filterfunction = function (v) { return (“” + v).indexOf(filter) !== -1;}
    }
    }
    for (var i in optionValues)
    {
    if ((filterfunction === null) || filterfunction(optionTexts[i]))
    sOptions[sOptions.length] = {
    value: optionValues[i],
    text: optionTexts[i]
    };
    }
    }
    return sOptions;
    }
    The first thing I noticed was that the method takes in 2 variables rather than the object that is specified in the documentation.

    I tried to step through the method but it looks like it’s failing when it gets to `if (dropdown)`, I assume this may be because getType isn’t returning select so it’s trying to use getMultiDropdown instead?

    Anyone have any ideas?
    This is a cached copy. Click here to see the original post.

You must be logged in to reply to this topic.