Is client.request.invokeTemplate accessible inside iparams.js?

My iparams.json contains param like this:

    "setFieldsMapping": {
        "display_name": "Want to map field?",
        "type": "checkbox",
        "default_value": false,
        "events": [
            {"change": "setFieldsMappingChange"}
          ]
    },
    "destinationField": {
        "display_name": "Choose field to save value",
        "description": "Choose field to save value",
        "type": "dropdown",
        "required": false,
        "visible": false,
        "options": [], //would like to set option with list of custom fields
        "default_value": []
    }

Than inside iparams.js I would like to retrieve from Freshsales account list of Custom Fields using API call e.g. client.request.invokeTemplate(…)

function setFieldsMappingChange(arg) {
  let myCustomFields = await client.request.invokeTemplate("getCustomFields", {})
  utils.set("destinationField", {Values: [myCustomFields]})
}

but I receive error:

Uncaught TypeError: Cannot read properties of undefined (reading 'request')
    at setFieldsMappingChange (iparams.js:37:19)

Is it possible without creating custom iparams.html page?

Found solution.

In iparams.js:

function onFormLoad() {
  app.initialized()
  .then(_client => {
      window.client = _client;
      console.log(' onFormLoad ')
    },
    error => {
      console.log("ERROR:Problem in fetching  from client");
    }
  );
}

and then can use client.request.invokeTemplate(…) in other function from iparams.js:

function checkAccountID(newValue) {
  console.log("checkAccountID : ", newValue);
  
  var p = new Promise(function(resolve, reject) {
    client.request.invokeTemplate("getCustomFields", {})
    .then(
      result => {
        console.log("checkAccountID result: ", result.response);
        resolve();
      },
      error => {
        console.log("checkAccountID Error", error)
        // Upon failure - send an appropriate validation error message
        reject("The account does not exist.");
      }
    );
  });
  return p;
}

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