Custom ajax handler for custom fields?

I’m trying to add custom ajax code for some custom fields. Basically, my goal is to let the user enter an order number into a custom field. Ajax will then send the value that was entered, using onChange, to a handler file. This file will submit an API request to an internal service which will return customer and other information about the order. Finally, the handler will package up the information using JSON, and send it back. The success handler in the ajax request will set the values of some other custom fields using the data from the JSON. With an order number, the user gets several fields filled in.

So far, I can submit the request. I’ve modified a local copy of html/Elements/EditCustomFieldFreeForm, using Perl to check the ID of the field being modified. If it’s equal to the ID of the field I want to give this extra functionality to, I make a request to local/html/Helpers/ajax/CFHandler.pm. This is where the problem is.

CFHandler.pm started as a Perl file, but today, I tried to use Mason syntax instead. No luck either way. For now, I just want to log something to the RT log, to be sure the file is being executed. I’ve not been able to do this. I’ve tried a bunch of approaches, but I don’t know enough about RT’s templates to know what I’m doing wrong. It could also be that EditCustomFieldFreeForm doesn’t appear to have access to RT->Config, so I can’t get the WebPath setting to properly set the URL. When I alert this value, it’s always blank.

  • Where does RT come from? Many templates have a variable called RT, which lets them access the logger, configuration, and other critical variables. How do they get it?
  • Does RT have a better way to do what I’m trying to do? I know I could use scrips on ticket creation or modification, but I’m told that doing that isn’t a great option. Users can’t see the values that are auto-filled until after the changes are complete; my boss wants the changes to appear in real time, so users can catch mistakes. Scrips would be a whole lot easier, but I’m told to try to get ajax working first.
  • Is there documentation for customizing ajax? It’s possible to customize a lot about RT, and the wiki has some good information that’s not in the official documentation, but I’ve never fond anything about ajax.

Thanks for any help or suggestions anyone has.

I’m no developer but an architect. So two hints, more or less usefull.

We use Ajax within RT for several years. I don’t know we use modules. But I know that we do not log this requests to RT.log. There is no need in our environment. The developer write their own logfile for debuging purpose only. They do it even in the copies of the frontend in local/html/. Maybe they use syslog, anyway.

Analyze your workflow: How does the agent open the ticket? What is the way he comes from? Maybe it is a solution to open the ticket via API or URL. So the agent searches the customer or the order in the ordersystem and use a specific button or link to open the ticket. All possible CF are filled.

I asked about the option of opening a ticket from a different page. It’s a no-go, apparently. People don’t want another webpage to deal with, and I can’t integrate the functionality into our order system directly because it runs on an IBM I system which is controlled via a terminal program.

Update: making my ajax handler a Mason template seems to have worked, partly. My log statements work, but I can’t figure out a way to get the POST data JS sends the handler, and RT renders my template. Instead of returning JSON in the handler, I get a string that is RT’s footer in HTML. I’m not sure how to stop this from happening, but neither do I know how to make this work by using a plain Perl file instead of a template.

1 Like