Getting domainName in iparams.js

I am trying to dynamically populate a multiselect in the installation parameters. The first step, I believe, would be to get the domainName so I can make API calls, but client.data.get(“domainName”) returns the error “Error: Cannot read properties of undefined (reading ‘get’)”. What am I doing wrong here?

Note: since I don’t know the event name equivalent to “onLoad”, I’m temporarily firing the JS on “change”.

iparams.json:

“authorized_roles”: {
“display_name”: “Authorized roles”,
“description”: “Please select the agent roles authorized to submit solutions articles”,
“type”: “multiselect”,
“required”: true,
“default_value”: “Admin”,
“options”: [“Admin”, “Knowledgebase Manager”],
“events”: [
{“change”: “getAuthorizedRoles”}
]
}

iparams.js:

var clientAPP = null;

document.addEventListener(“DOMContentLoaded”, function () {

app.initialized()
    .then(initAPP)

});

initAPP = function (_client) {
clientAPP = _client;
};

async function getAuthorizedRoles(clientAPP) {

var authorized_roles = new Promise(function (response) {

    try {

        var domainName = clientAPP.data.get("domainName");
        return domainName;

    } catch (err) {
        alert("Error: " + err.message);  //Returns "Error: Cannot read properties of undefined (reading 'get')"
    }
})

.then(function (domainName) {
    alert("DomainName" + domainName);
})

@WardenBrown,
Good Day!
You are not able to use the clientAPP.data.get("domainName"); in the Iparams page (settings page)

Instead, you need to get the value from the user (user entered) and then make the API call on the change event of that field.

or you can use the domain and api_key type, refer here for how to use API and domain type and then use the data-bind feature to auto-populate the domain and API key.

Note: since I don’t know the event name equivalent to “onLoad”, I’m temporarily firing the JS on “change”

for this Question → there is a function which is available,
onFormLoad() and onFormUnload() function. The onFormLoad() is a callback function that is triggered when an Installation page is loaded, during app installation. The onFormUnLoad() is a callback function that is triggered when the Settings page, where the app user enters values for the installation parameters (it is not documented in freshservice website :frowning: but it is available in this site under Make your installation page dynamic)

and you can use the utility methods to get/set the values.

let me know if you need more information. :slight_smile:

Thanks