- Stefan Hulls
Mail interface to small external provider 1

Prerequisites if you like to try it:
You already have an ITPR demo account. If not, you can easily request one with demo data.
You already signed up for a techwork automator demo account. If not, goto the registration blog post.
Business case:
Having a small specialized service provider with a homegrown Service Management tool often rises the integration question. Of course, there are various options. The best one is that the small service provider uses it’s own ITRP account and you simply create a trust.
Sometimes, this is not possible for whatever reason. Easiest is to integrate via email. In my demo example I use GigaTera to showcase that scenario – even though GigaTera has it’s own ITRP account, therefore I pretend they don’t have one.
Now, you probably ask the question, why we need to write a couple of lines of automator code for that and not use the standard ITRP email functionality? Answer: The requests may go back and forth between the external provider and the internal team and I want exactly the same assignments if information comes back from GigaTera.
How does the request go back and forth?
To the external service provider (GigaTera): The internal team (in my example the windows server team because the affected service instance is “Windows for Email”) simply applies the “SAN1 for Widget Houston” service instance, to assign the request to the GigaTera team. This assignment triggers the automator package that sends the email. I apply the service instance and avoid “manual” Team changes because I want all Service Level agreements to be correct. (Subject of this blog post).
Back from the external service provider: On the other hand the external provider most likely sends an email with information back to us. What I want to achieve is that the Service instance “Windows for Email” is automatically applied alongside the “old” team and member. If a team member was assigned I want this team member to work again on the request. In short the request should have the same meta data as before plus information from the external provider. (Subject of the next blog post).

To achieve that I simply write data to the “custom_data” field. I remember the team id, the member id and the service instance id. No custom data will be erased or overwritten, we just add data from the audit.
...
$custom_data = request.custom_data;
$custom_data.wdc_team_id = request.audit_old_team.id;
$custom_data.wdc_member_id = request.audit_old_member.id;
$custom_data.wdc_si_id = request.audit_old_service_instance.id;
update('requests', request.id, {
custom_data: $custom_data
});
...
The ITRP record with its custom data:

The complete script:
log('******* External Provider mail interface - create request ********')
mergeAudit(request);
log(request);
if (request.audit_is_changed_team && request.audit_new_team.id == $GigaTera_Storage_Team) {
$custom_data = request.custom_data;
$custom_data.wdc_team_id = request.audit_old_team.id;
$custom_data.wdc_member_id = request.audit_old_member.id;
$custom_data.wdc_si_id = request.audit_old_service_instance.id;
update('requests', request.id, {
custom_data: $custom_data
});
for(let note of request.notes) {
$lastNote = note.text;
}
$mailData.to = 'klaus@techwork.at';
$mailData.subject = 'Widget Data Center - Request #' + request.id;
$mailData.body.text = 'Requested by: ' + request.requested_by.name +
'\nService Instance: ' + request.service_instance.name +
'\nImpact: ' + request.impact +
'\n\n\nLast Note: ' + $lastNote
sendMail($mailData);
$date = date();
$m = moment($date);
$tz = $m.tz("Europe/Vienna");
$tzDate = $tz.format("DD.MM.YYYY, HH:mm");
update('requests', request.id, {
note: '```' + $tzDate + ' -- Request email to GigaTera has been sent ...```'
});
}
log('******* External Provider mail interface - create request END ********');
Interesting to note:
I also write a note to the request with a timestamp to indicate that the email has been sent on a particular date and at a particular time.
The timestamp can be formatted in various ways because the automator integrates the “moment.js” framework. This framework parses, validates, manipulates and displays dates.