Is it possible to get dropdown options from iparam.json inside iparam.js?

I have created a iparam.json page where one of the multiselect fields needs its options populated by an API call (more specifically give the user a selection of available custom fields in the account). The field looks like this:

    "customFields": {
        "display_name": "Custom fields",
        "description": "Please select custom fields to show in the App",
        "type": "multiselect",
        "options": [],
        "default_value": [],
        "visible": false
    }

In my iparam.js file I created a function that dynamically shows or hides the field, depending if a valid API key has been entered in the API key field. This function also fills the options for the “customFields” field above.
Now I would like to check if the field already has options (options array length > 0) so the Web request to fetch the fields is triggered only once, but I as far as I could see there was no function to get the “options” attribute of an iparam fields, only its value.
I think I could theoretically put a global boolean in iparam.js that I set once the field options have been set, but if possible I would rather use another option.

Here is the function (triggered on change event in the API key field) for reference:

function apiKeyChange() {
    if (utils.get("apiKey").length == 20) {
        const p = new Promise((resolve, reject) => {
            client.request.invokeTemplate("validateAPI", {
                "context": {
                    "apiKey": utils.get("apiKey"),
                    "domain": utils.get("domain")
                }
            }).then(() => {
                resolve();
                utils.set("systemFields", { visible: true });
                utils.set("customFields", { visible: true });
                setCustomFieldOptions();
            }, () => {
                reject("Invalid API key");
                utils.set("systemFields", { visible: false, value: [] });
                utils.set("customFields", { visible: false, value: [] });
            });
        });
        return p;
    }
    else {
        utils.set("systemFields", { visible: false, value: [] });
        utils.set("customFields", { visible: false, value: [] });
        return "API key should be 20 characters long";
    }
};

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.