Approve tickets based on requester

Hi Gurus,

Is there a way to approve a ticket based on requester’s email / User? If the requester is me, I don’t approve (So, no extra ticket to be created). If the requester is someone else, a new ticket will be created.

Thanks
Katrina

Are you referring to the approvals workflow, where when a ticket is created a linked approval ticket is generated?

Thanks @knation for your reply.

yes I am referring to the approval system.

Actually, I am USER1 and set up my self as an Approver. Everyone who create a ticket, a new ticket is created and assigned to me (USER1) for approval, which it makes sens.

But when I create a ticket by myself (USER1) in the system, it does not make sens to approve my own ticket. I want another user (USER2) to approve the ticket I create. Which means the new ticket created should be sent to another user for approval (Let’s say USER2)
Is there a way to configure this behavior?

There isn’t a way to configure this, but you can write a little Perl code inside of the email template that creates the approvals ticket to check who created the ticket and then decide who the owner should be.

The example template from the docs:

  ===Create-Ticket: Manager approval
    Subject: Manager Approval for {$Tickets{TOP}->Id} - {$Tickets{TOP}->Subject}
    Depended-On-By: TOP
    Queue: ___Approvals
    Owner: root
    Requestors: {$Tickets{TOP}->RequestorAddresses}
    Type: approval
    Content-Type: text/plain
    Due: {time + 3*24*60*60}
    Content: Please approve me.

    Thanks.
    ENDOFCONTENT

You’d just want to do some embedded Perl stuff to decide between USER1/2 for the owner field:

  ===Create-Ticket: Manager approval
    Subject: Manager Approval for {$Tickets{TOP}->Id} - {$Tickets{TOP}->Subject}
    Depended-On-By: TOP
    Queue: ___Approvals
    Owner: {
    if ( $Tickets{TOP}->RequestorAddresses =~ /USER1\@example\.com/ ) {
          $OUT = 'USER2';
    }
    else {
        $OUT = 'USER1';
    }
}
    Requestors: {$Tickets{TOP}->RequestorAddresses}
    Type: approval
    Content-Type: text/plain
    Due: {time + 3*24*60*60}
    Content: Please approve me.

    Thanks.
    ENDOFCONTENT

I’d also suggest using groups rather than users - makes it easier to scale in the future (multiple potential approvers) and deal with absences, people leaving, etc without having to hunt down and change the templates.

I just did a fresh installation. I gonna test both solutions using users and groups. :slight_smile:

1 Like

Hi

You can use a custom scrip. Basically, you want to check if the requestor is the same as the approver and if they are the same, you want to set the ticket status to ‘Approved’ and return 0
Here is an example:

Create a custom script using:
Condition: User Defined
Action: Create Tickets
Template: Use you create approval template

my $ticket = $self->TicketObj;
my $requestor= $ticket->Requestors->UserMembersObj->Next->Name;

return 0 unless $type eq "Status";
return 0 unless $ticket->Status eq 'pendingApproval';
 
if(($requestor eq $ticket->FirstCustomFieldValue('Approver')){

        $ticket->SetStatus('Approved');
        return 0;
}

Hi @knation,
Sorry for the delay. I did not forget you :slight_smile:
Your above solution worked like a charm :slight_smile:
I got some positive feedback from our client about the overall system. The fact that we can customize it using scripts is very helpfull.
Again, thanks for your support,

1 Like

Hi iacob28,
Thanks for your response. Yes your solution also worked with a little twaeking.