Front end App is not working properly in production

The developed frontend custom App is working fine in customer’s sandbox. It behaves inconsistently when it is moved to customer’s production environment.

Using installed front end App , I tried to update the tickets. Sometimes the App is initiated, works fine and also shows all the logs which are I embedded in my code. Sometimes the App is not initiated and also not able to get any logs too.

Thanks,

1 Like

@Priya_Dharshini
Hi, Is you app contains middleware too?if Yes it may due to failure of API response, If not try to remove commented code or it may shows you in console what is going on so u may share it here.

2 Likes

@Priya_Dharshini Please also check if app is failing at initialization, or some other calls. For that, print your every error in the catch block.
Else please share your piece of code here so we can further help you out.

2 Likes

@Priya_Dharshini,

This might like have to do something to do with JS.

  1. Can you help us sharing a code snippet of JS file where app.initialized() happens?
  2. Also in the the HTML file where scripts are included. Just to notice the order in which scripts are included in the HTML.

Please feel free to remove any unnecessary code that you think might not be relevant for debugging.

I am sharing the piece of code used in my code.

$(document).ready(function () {
  app.initialized()
    .then(function (_client) {
      window.client = _client;
      console.log(headers, options);
      window.client.data.get('domainName')
        .then(function (data) {
          console.log("INSIDE domain");
          window.domain = data.domainName;
        });
      var eventCallback = function (event) {
        var event_data = event.helper.getData();
        console.log(event_data);
        event.helper.done();
        window.client.data.get("ticket").then(
          function (data) {
            console.log("INSIDE UPDATE"); console.log(data);
            let content = data.ticket;//,j = 0;//k;, id=[]
            console.log("content......", content);
            console.log("content.custom_fields.cf_test"); console.log(content.custom_fields.cf_test);
          },
          function (error) {
            // failure operation
            event.helper.fail(error)
          }
        );
      };
      window.client.events.on("ticket.propertiesUpdated", eventCallback);
    });
});

Please find the attachment below.

Sometimes App is initiated and throws logs too.rar (695.0 KB)

@Priya_Dharshini,

:arrow_heading_up: Can you please eloborate on what do you mean by ‘customer’s sandbox’ here? Is it local evironment running on fdk ?

As per documentation,


So, your logs added to the code are being executed when Freshservice page loads. It is not ‘sometimes’ but it is very certain that INSIDE domain will be logged to console when page loads for the first time.

To better handle this, please use next event as part of app life cycle,

For reference only, I tried to refactor the code,

document.onreadystatechange = whenInteractive;

function whenInteractive() {
  if (document.readyState == 'interactive') {
    return app
      .initialized()
      .then(function appLogic(_client) {
        window.client = _client;
      })
      .catch(console.error);
  }
}

client.events.on('app.activated', observePropUpdate);

function observePropUpdate() {
  client.data.get('domainName').then(function logDomain(payload) {
    window.domain = payload.domainName; // not encouraged to pollute global scope
    console.log(payload.domainName);
  });

  client.events.on('ticket.propertiesUpdated', seeFields);

  function seeFields(event) {
    let event_data = event.helper.getData();
    event.helper.done();
    client.data
      .get('ticket')
      .then(function staring(data) {
        console.log('INSIDE UPDATE');
        console.log(data);
        let content = data.ticket;
        console.log('content......', content);
        console.log('content.custom_fields.cf_test');
        console.log(content.custom_fields.cf_test);
      })
      .catch(function failEvent(error) {
        event.helper.fail(error);
      });
  }
}

Please let me know if that helps.

1 Like