Customer Survery script not running on set to resolve

I am trying to make a scrip that sends customer survey on status sent to resolved or work finished(resolved from a different lifecycle). Using a custom field(‘Survey Sent’) to store survey status to avoid sending multiple times on a a single ticket if case of reopen or sets to “Don’t Send Survey” ever if the ticket is rejected. Right now It only sends survey if on comment or correspondence on a already resolved ticket instead of sending it on being resolved. Below is script.

User Defined Condition:

  if( ( ($self->TicketObj->Status eq "resolved") || ($self->TicketObj->Status eq "Work Finished") ) && ($self->TicketObj->FirstCustomFieldValue( 'Survey Sent' ) eq 'No') ) {
    $self->TicketObj->AddCustomFieldValue(
      Field => 'Survey Sent',
      Value => 'Yes');
    return 1;
  }

  if( ($self->TicketObj->Status ne "resolved" || $self->TicketObj->Status ne "Work Finished") && ($self->TicketObj->LifecycleObj->IsInactive($self->TicketObj->Status)) ) {
    $self->TicketObj->AddCustomFieldValue(
      Field => 'Survey Sent',
      Value => "Don't Send Survey");
    return 0;
  }

}

return 0;

This code:

$self->TransactionObj->Type eq “Comment” || $self->TransactionObj->Type eq “Correspond”)

Means it only runs for a comment or a correspond, you also want to check if the update is a status update to your resolved status.

1 Like

I ran the following debug script to help figure out of some of my problems on every comment or correspondence.

RT::Logger->debug("**LOOK HERE** Transaction type is".($self->TransactionObj->Type));
RT::Logger->debug("**LOOK HERE** Ticket Status is".($self->TicketObj->Status));
RT::Logger->debug("**LOOK HERE** Ticket Status equals Work Finished?".($self->TicketObj->Status eq "work finished"));

It was logging everything twice once.
Once saying the type was Comment or Correspond
Second saying the type was Status

The Status was the old status not what the status was changed to.

So my problem is the status doesn’t change till the comment or correspond is finished. I am not sure how to fix the timing yet.

A single interaction with RT may turn into a fistful of transactions. For example doing a jumbo update to set the status, make a comment, add a CC, and set two custom fields will result in 5 transactions - one per piece.
Your condition needs to check the one part of the interaction that you’re interested in. If you need to access other parts of your interaction then set the scrip to run in batch.

1 Like

@Jeff_Voskamp thank you for that. I moved to checking for transactions that type are “Status” and I made a lot of head way. Testing below tomorrow.

## Still need a way to pull and compare against just the first inactive status
if($self->TransactionObj->Type eq "Status") {
  if($self->TransactionObj->NewValue eq "work finished" || $self->TransactionObj->NewValue eq "resolved") {
    if($self->TicketObj->FirstCustomFieldValue( 'Survey Sent' ) eq 'No'){
      $self->TicketObj->AddCustomFieldValue(
        Field => 'Survey Sent',
        Value => 'Yes');
      return 1;
    }
   }
  if($self->TransactionObj->NewValue ne "work finished" || $self->TransactionObj->NewValue ne "resolved") {
    if($self->TicketObj->LifecycleObj->IsInactive($self->TransactionObj->NewValue) ){
      if($self->TicketObj->FirstCustomFieldValue( 'Survey Sent' ) eq 'No'){
        $self->TicketObj->AddCustomFieldValue(
          Field => 'Survey Sent',
          Value => "Don't Send Survey");
        return 0;
      }
    }
  }
}
return 0;