l.interfaceAPI[e.method] is not a function

I am trying to create a very simple app to enable a 1-click “pickup” option when reading a ticket. I’d like to create a button that an agent can click to pick up a ticket. I understand it’s very easy to pick up tickets already, I’m just trying to see if I can make it marginally easier.

image

The button here works, to retrieve the user_id of the logged in user, but when I attempt to use client.interface.trigger(“SetValue”, {id: “agent”,value: user_id }) it doesn’t work, and I get the “uncaught TypeError” seen in the title. There must be something I don’t understand about how to use interface methods.

My code currently is this:

document.onreadystatechange = function() {
  if (document.readyState === 'interactive') renderApp();

  function renderApp() {
    var onInit = app.initialized();

    onInit
        .then(function getClient(_client) {
            window.client = _client;
            client.events.on('app.activated', assignAgent);
        })
      .catch(handleErr);
    }
};

function assignAgent() {
  client.data
    .get('loggedInUser')
    .then(function(payload) {
        console.log(`Current user_id: ${payload.loggedInUser.user_id}`);
        client.interface.trigger("SetValue", {id: "agent",value: `${payload.loggedInUser.user_id}` });
    })
    .catch(handleErr);
}

The console.log does output the correct user_id, I just cannot set the agent value to user_id.

Sorry if these are stupid questions, I am quite new to this.

1 Like

I don’t know about Freshservice, but in Freshdesk the user_id and the agent_id are integers rather than a string. If I’m not incorrect it seems like you are setting a string when setting the value for the agent rather than an integer.

Something else, we use a similar App in Freshdesk (custom app) and we found that when you just use the interface API to set the agent_id it still depends on the agent clicking the update button before it actually gets saved (if it works the same way in Freshservice). We instead do an API call using the request method to set the agent_id and then additionally set the user_id with the interface method incase the updated via api call doesn’t directly reflect in the ticket :slight_smile:

3 Likes

@rphillips
Welcome to the community!

I hope you are setting the value on ticket details page :thinking:
otherwise it won’t work

if you are setting it on ticket details page, do let us know, we will try to reproduce it,
mean while try to set the value as int instead of string and check if that works.

Thanks

2 Likes

Interesting, I’ll need to read up on the API call methods to see if I can get it working that way. Converting the user_id to an int has not seemed to make any difference, but in reality the problem is more likely with something I don’t understand.

Yes, when I pull up the ticket details page (There is no helpdesk here!) the button exists, but clicking it does not change the assigned agent. It will print out my test string “current user_id: 19001092930” but the “SetValue” portion of the code does not seem to work.

I changed that line to the following to see if I can get it working, but there has been no improvement:

client.interface.trigger("SetValue", {id: "agent",value: parseInt(`${payload.loggedInUser.user_id}`) });

@rphillips.
let me check and get back to you at earliest
if you don’t mind can you please share us the app Zip to debug further?

Thanks

1 Like

Sure, I ran the fdk validate and fdk pack commands to generate the attached zip, hopefully that works!

fs_app.zip (4.5 KB)

Thank you so much for taking the time to look into this for me, it’s really not terribly important but I would love to learn how to do this.

@rphillips,
Good Day!
I found the issue, there is an syntax error in your code SetValuesetValue

client.interface.trigger("setValue", {id: "agent",value: parseInt(`${payload.loggedInUser.user_id}`) });

try with the above code snippet

Hope it helps :slight_smile:

Thanks

3 Likes

Oh my gosh, I feel like such a fool.

That solves that problem, it just doesn’t of course update the ticket itself without me clicking the Update button. I think I’ll revisit @Thomas_Haitsma’s suggestion to use an API call if that’s the only way to make this truly “one-click”.

Again, thank you so much!

1 Like

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