Coming soon: Your brand new Help Center & Community! Get a sneak-peek here

Change logic on Reply button

Hi,

I'm just looking to see if anyone has changed the logic of the standard "Reply" button from a request?

I would like to add an if-statement to check values on some more fields, if they are filled out, do one thing, if not do another.

Has anyone changed the logic on it? If so, how would I go about to do it?

One approach would be to add another button to add the logic to, but I would prefer to change the standard button (to make life easier for the users).

RE: Change logic on Reply button

I do not think this is possible when those buttons are part of the message component in the ej_viewTicket_80.

Av: Konrad Gislerud Andresen 19. jun 2018

RE: Change logic on Reply button

Cheers Konrad. Good to know it can't be done. Guess the only way would be to hide the standard button and implement my own and then put all the logic there (including standard, which would be waaay too much work).

I'll just make another button for the specific purpose.

Av: Rikard Fredlund 20. jun 2018

RE: Change logic on Reply button

Hi Rikard,

You can use the Screen Chooser for the Reply to customer, then depending on the if statement set the url of the web page the users goes to when clicking the Reply button.

#setLanguageLevel 3;

// Re-direct to custom screen FOR EDIT REQUEST, ACTIONTYPE = 2

String entryId = getCgiVariable("entryId");
if (entryId == "")
  entryId = getCgiVariable("ticketId");

Ticket t;

if (entryId.toInteger() > 0)
{
  t.load(entryId.toInteger());
}

String copyToAll = getCgiVariable("copyToAll");

if (copyToAll == "true")
{
  copyToAll = "&copyToAll=true";
}
else
{
  copyToAll = "";
}

setVariable("url", getProgram(1)+"&action=doScreenDefinition&idString=ej_myEditTicket&action=addMessage" + copyToAll + "&entryId=" + entryId + "&actionType=1");

 

Trevor

Av: Trevor Sharp 22. jun 2018

RE: Change logic on Reply button

I tried the approach with screen chooser here, but i just couldn't get it to work as I wanted.

So i took another approach (keep in mind the code is only in test stage, so nothing perfect. But it seems like an applicable approach).

What i did is the following:

I created a custom screen: ( View Ticket 80 copy )

I point towards this screen in screen chooser.

At the top of this screen i added an ejScript.

In the body of this ejScript i added the following jQuery (keep in mind, work in progress).

What i wanted to do is: check if a certain extra field (type: Request relation ) has a value. If it does, I unbind the standard events of the "Reply" button and add my own event (this is the work in progress part, right now it opens the related request in a new tab):

String jQuery =
"
    <script>
        $(document).ready(function () {

            //var ary = [];
            $(function () {
                $('.HtmlInfoFields2_subTable tr').each(function (a, b) {
                    var name = $('.HtmlInfoFields2_label', b).text();
                    var value = $('.HtmlInfoFields2_value a', b).attr('href');
                    if (name == 'ticketrelation3:')
                    {
                        if (value.substring(65) != '')
                        {
                            var buttons = $('.HtmlMessages2_button').map(function () { return this; });

                            $.each(buttons, function (key, value) {
                                //alert(value.innerHTML);

                                if (value.innerHTML == 'Reply') {
                                       $(value).unbind();
                                       $(value).bind('click', function ()
                                       {
                                           window.open('ticket.fcgi?_sf=0&action=doScreenDefinition&idString=ej_viewTicket_80_copy&_sf=0&table=ticket&entryId=22&ticketId=22','_blank');
                                       });
                                   }
                               });
                        }
                    }
                });
            });
          });
    </script>
";
print(jQuery);

Av: Rikard Fredlund 6. jul 2018

RE: Change logic on Reply button

Here is my updated jQuery code.

What I do is:

First check if a more field has a value. If it does, unbind logic of Reply button (including post event) and replace it with a new event.

When reply button is clicked, I come to the related request and into "add message" of that request.

String jQuery =
"
    <script>
        $(document).ready(function () {

            $(function () {
                $('.HtmlInfoFields2_subTable tr').each(function (a, b) {
                    var name = $('.HtmlInfoFields2_label', b).text();
                    var value = $('.HtmlInfoFields2_value a', b).attr('href');
                    if (name == 'ticketrelation3:')
                    {
                        if (value.substring(65) != '')
                        {
                            var id = value.substring(65); // The ID of related request
                            var url = 'http://support.yourdomain.com/scripts/ticket.fcgi?_sf=0&action=editTicket&actionType=1&ticketId=' + id;

                            var buttons = $('.HtmlMessages2_button').map(function () { return this; });

                            $.each(buttons, function (key, value) {

                                if (value.innerHTML == 'Reply') {
                                       $(value).unbind();
                                       $(value).bind('click', function ()
                                       {
                                           event.preventDefault(); // Because the button Always used to post, I had to remove that behaviour.
                                           window.open(url,'_self');
                                       });
                                   }
                               });
                        }
                    }
                });
            });
          });
    </script>
";
print(jQuery);

Av: Rikard Fredlund 6. jul 2018