IT Monkey will place code here as examples of what Cireson's consulting team has to offer as well as examples for public consumption to benefit the Microsoft System Center community as a whole.
DISCLAIMER
All files and projects located here come as is and without any warranty or support. We will attempt to improve the projects as time goes on based on customer and community demand. Comments and improvements are welcome as well as customization requests. Your use of these Cireson Uploads is subject to our Terms of Use.
Cireson's support team has no information on these projects outside of what you have available and will not provide support for these enhancements, extensions, and scripts.
Dont forget to checkout solutions uploaded by our customers, partners and community members here.
Portal Tip - Adding an email link for the affected user to the incident form
app.custom.formTasks.add('Incident', null, function (formObj, viewModel) {
formObj.boundReady(function () {
$("label[for='RequestedWorkItem']").parent().append("<span id='affectedUserEmail' class='help-block'></span>");
var fnLookUpUser = function(lookupUserId){
$.get("/api/V3/User/GetUserRelatedInfoByUserId", { userId: lookupUserId },
function (data) {
if (data.length > 0)
{
var obj = jQuery.parseJSON( data);
var strEmailLink = "";
if (typeof obj.Email != "undefined" && obj.Email.length > 0)
{
var emailTo = obj.Email;
var irTitle = (pageForm.viewModel.Title) ? pageForm.viewModel.Title : "";
var emailSubject = "[" + pageForm.viewModel.Id + "] " + irTitle;
var emailCC = "scsmserver@contoso.com";
strEmailLink = "<a href='mailto:" + emailTo + "?cc=" + emailCC + "&subject=" + emailSubject + "'>" + emailTo + "</a>";
$("#affectedUserEmail").html(strEmailLink);
}
else
$("#affectedUserEmail").html("");
}
else
$("#affectedUserEmail").html("");
},"json");
}
if (pageForm.viewModel.RequestedWorkItem.BaseId)
fnLookUpUser(pageForm.viewModel.RequestedWorkItem.BaseId);
boundObj["RequestedWorkItem"].bind( "change",
function( objEvent, objData ){
var affectedUserId = (pageForm.viewModel.RequestedWorkItem.BaseId) ? pageForm.viewModel.RequestedWorkItem.BaseId : "";
fnLookUpUser(affectedUserId);
});
});
});
Comments
Thank you so much! This is exactly what I was looking for.
Old post, however wanted to say Thank You @John_doyle for providing this to the committee.
This is great way to help give a personal feel/touch to email compared to the Send Email task.
Thanx for the code, very useful. I wonder if you could help with the following regarding the publishing of the email address. We are busy migrating from Lotus notes email to Outlook. As we have not fully migrated all users / analysts when a user clicks the link it will try to load the local mail client and in this case it would be outlook. If they are still using Lotus notes it will try to go through the process of installing outlook. I was hoping there is a way to hide the email address from users and only analysts will have the option to see the email address. I know it is a long shot but thought I would ask
Kind regards
Eugene
Just replace "SCSMEMAIL" with your service manager email account.
How can I add a link to the ticket in the body of the email?
window.location.href = "mailto:" + emailTo + "?cc=" + emailCC + "&subject=" + emailSubject;
And simply would have to be updated to -
window.location.href = "mailto:" + emailTo + "?cc=" + emailCC + "&subject=" + emailSubject + "&body=" + emailBody;
Where "emailBody" is a variable declared before this in each Work Item section to the effect of -
emailBody = "https://portalName.domain.tld/Incident/edit/" + pageForm.viewModel.Id
However if I'm not mistaken the mailto: method in HTML enforces plaintext preventing a short link from being generated. As a result, if you take the steps above you'll just end up with the entire URL in the body of the email. But if that isn't a showstopper, than awesome!
Given that the affected user rarely changes and the form will probably be saved before they choose to use the task, it is probably not an issue anyway.
Hi Guys.
Thanks for this great code John. We have a few email addresses with an apostrophe in the surname. The mailto breaks in these scenarios. Any tips to fix this?
Thanks
Nicola
Try changing the line
to:
var emailTo = encodeURIComponent(obj.Email);
That should escape any special characters in the email addresses.Well, it seems that encodeURIComponent does not escape single quotes.
Try this instead:
var emailTo = obj.Email.replace(/'/g, "%27");
The actual change can be seen here:
//$("label[for='RequestedWorkItem']").parent().on("click", "a", function (e) {
$("#affectedUserEmail").on("click", "a", function (e) {