• Stefan Hulls

Send mail to “Requested for” status “Waiting for Customer”

Prerequisites:

  1. You already have an ITPR demo account or a production account. If not, you can easily request one with demo data.

  2. You already signed up for a techwork automator demo account. If not, goto the registration blog post.

Business case:

ITRP provides out of the box the capability to request something for someone else. This can be done in Self Service or in the Servicedesk console via the “Requested for” field. To make it easer lets assume “Beatrice Baldwin” – the “Requested by” person,  requests “New Software” for “Matt Leach” – the “Requested for” person.

Both, Beatrice and Matt get an email on submission and completion.

If the Service Desk person who handles the request has a question, he/she simply sets the status to “Waiting for customer” and enters the question into the note field. Beatrice then gets an email. Matt does not. The package below sends an email to Matt too, if the status is “Waiting for customer” – this is all you need (a version with comments is provided after the email screenshot).

$request = request;
mergeAudit($request);

if (($request.requested_for.id != $request.requested_by.id) &&
    $request.status == 'waiting_for_customer')
{
  $mailData = createTemplateHTMLMail('request-watch-all-notes');
  $mailData.to = $request.requested_for.primary_email;
  sendMail($mailData);
}


The email Matt gets

The code with comments


//
// send waiting for customer email to Requested for person too
// not only to the Requested by person
//

log('** Send "Requested for" "Waiting for Customer" Begin **');

$request = request; // universal request template prerequisite
mergeAudit($request); // inject audit information

//check if requested for and requested by are different
if (($request.requested_for.id != $request.requested_by.id) &&
 $request.status == 'waiting_for_customer')
{

// request-watch-all-notes is defined in 'Templates',
// uses $request
$mailData = createTemplateHTMLMail('request-watch-all-notes');

$mailData.to = $request.requested_for.primary_email;

sendMail($mailData);
}

log('** Notification END**');



Interesting to note

The mail is sent out on each update of the request as long as the status switches to, or is “Waiting for Customer”.

...//check if requested for and requested by are different
if (($request.requested_for.id != $request.requested_by.id) &&
    $request.status == 'waiting_for_customer')
{
... 

The if condition checks first if the “Requested for” is different to the “Requested by” id. Then it checks wether the status is “Waiting for Customer” or not.

If you want to send the email only if the status switches to “Waiting for Customer” the if condition needs a minor modification:

...//check if requested for and requested by are different
if (($request.requested_for.id != $request.requested_by.id) &&
   $request.audit_is_changed_status &&
   $request.status == 'waiting_for_customer')
{
... 

Audit data

...$request.audit_is_changed_status...

returns true if the status changed. Such changes can be checked because of the “mergeAudit” function. This function merges audit information into an ITRP object and makes it possible to check “new” values against “old” values.

Share this:

  1. Twitter

  2. Facebook

Contact

Erdbergstrasse 52-60

1030 Wien

Austria

​​

Tel: +43 1 585 77 55

office@techwork.at

    © 2019 - techwork data gmbh