Read iparam not working in custom app

Dear,

I’m newbie in freshwork sdk, and i’m stuck since many hours on this simple problem:

  • I just need to read the iparam value (settings when app is installed).

Please see the iparams.json file:

{
  "testsetting": {
    "display_name": "url value",
    "description": "Description test",
    "type": "text",
    "required": true,
    "default_value": "http://test.com"
  }
}

In the App.js:

const BASE_URL = `<%=iparam.testsetting%>`;

isDocumentReady();

function startAppRender() {
  app.initialized()
    .then(function (client) {
		var _message = `START: `;
	  
	  	_message = _message + `<br />` +  `TEST1: ${BASE_URL}`;
	  	_message = _message + `<br />` +  `TEST2: <%= iparam.testsetting %>`;
		_message = _message + `<br />` +  `TEST3: ${client.iparams.get("testsetting")}`;

		const displayElement = document.getElementById('apptext');
		displayElement.innerHTML = `: ${_message}`;
  
    })
}

function isDocumentReady() {
  if (document.readyState != 'loading') {
    console.info('Browser waiting until DOM loads...')
  } else {
    document.addEventListener('DOMContentLoaded', startAppRender);
  }
}

Here the result:

: START:
TEST1: <%=iparam.testsetting%>
TEST2: <%= iparam.testsetting %>
TEST3: [object Promise]

Someone has an idea why it doesn’t work? I tried so many things…

Regards,
JC

You can see this is a promise:

TEST3: [object Promise]

You’ve got to wait until that is complete, then proceed. For example:

let iparamPromise = client.iparams.get();

iparamPromise.then((iparams) => {
  console.log(iparams);
});
4 Likes

Thank you Jamie for the fast answer, it works fine :wink:

1 Like