How do I email in user defined scrip?

Hi all,

I’d like to make a scrip to notify ticket requestors of transactions. However, I need it to conditionally email the owner, which means I have to write the code to do this. I can email using rt-crontool easily, but I don’t know how to do it in a scrip. Do I call RT::Action::Notify? If so, how do I give it the argument(s) I want? If not, what’s the right way? Thanks!

You can use the “Notify Requestors” Action in your scrip.

If you want to email the creator of the transaction, you can put { $Transaction->CreatorObj->EmailAddress } in your template ( ) You’d have to use the “Send Email” Action with this.

Thanks. How, though, would I use Notify inside a scrip? Or would I select it from the list of actions, then somehow adjust the arguments it gets in my user-defined code? Again, I’ve only used Notify in the context of rt-crontool, so I’m not sure how to approach it from the scrip side.

Just to be clear: You want a scrip where always the creator of a transaction gets an email and when a certain condition is met you want to email the owner of the ticket too?

Is there a reason you have to do this in a single scrip? Like the owner has to be Cc’d on the email?

Usually, the ticket requestor is the owner, because we have a scrip in place that forces this to happen. Because of this, we disabled email notifications to owners so that people didn’t get duplicate emails (one as the requestor, one as the owner). Now, though, some users have started to re-assign the owner, which is perfectly fine. The only problem is that the new owner never gets transaction emails, but the requestor does. This is, of course, because of the previously mentioned setting to never email owners.

What I want to do is, somehow, email the requestor, CCs, and owner, but conditionally. If the owner is the requestor, then only one or the other gets the email, along with any CCs. If the owner and requestor are different users, then both should get the email, again, along with CCs. I thought a scrip to determine which case should happen, then email, would be the easiest way. Is there a better way of doing this that I’m not thinking of? There probably is. :slight_smile: Thanks for any ideas.

How did you do this?

You could have one scrip where you use “Notify Requestor and CCs” and another scrip where you check if Requestor != Owner and “Notify Owner” if it’s not important to have the CCs correctly set on the mail.

It’s strange to me that you’re experiencing issues like this as I thought there already is some deduplication for mail recipients.

The second scrip you mentioned is what I don’t know how to do. I can check for equality, but how do I then send the email, or stop it sending? That’s where I’m stuck.

when you return 0; from your custom condition the scrip action is aborted ->

Good point, I could do this for the “notify owner” action. But how? I can select either “notify owner” or “user defined”, but not both. If I set it to be user defined, I’m back to my original question about the syntax to use RT::Action::Notify within the code of a user-defined scrip.

Scrips have a Condition and an Action. You need one scrip with Condition: On Correspond and Action: Notify Requestor and CCs and another with Condition: Custom Condition and Action Notify Owner. You have to check in your Custom Condition whether the transaction is of type “Correspond” and if Owner != Requestor.

Okay, I see how this works now. Thank you for the explanation. I’m having trouble with the details (I’m told User::PrincipleID is unimplemented) but that’s another post. At least now I understand how to do this, if only in theory for now.

Did you look at this?

I had, yes. I think I have it sorted now. Thanks again for your responses.