Pages

Tuesday, September 24, 2013

Format SharePoint People Picker as Hyperlink on Infopath Display list form

I wanted to display the people picker value in a list form as a hyperlink in SharePoint. By default, it was just a text field on the display form. In a normal SharePoint list form, this field can be modified to disable output escaping so that it formats as an html. I was totally unsure how to accomplish this, and pressed for time, I decided to write a script to format it as a hyperlink. If you know how to do this in InfoPath, please share!

Place this script in a content editor webpart on the display list form:

<script type='text/javascript' src='/js/jquery-1.7.2.min.js'></script>
<script type="text/javascript">

//make sure document is loaded first
$(document).ready(function() { 
 setTimeout(formatUserField,'1000');
});

function formatUserField()
{
 $("span[ScriptClass='CustomControl']").each(function(){
  var curValue = $(this).text();
  var newhtml = "<a href='javascript:void(0)' onclick='PopUpEmail(\"" + curValue + "\");return false;'>"+ curValue +"</a>";
  $(this).html(newhtml);
 });
}

function PopUpEmail(username)
{
    var p_recipient = username;
    var p_cc = "";
    var p_subject =  "";
    var p_body =  "";
    var objO = new ActiveXObject('Outlook.Application');     
    var objNS = objO.GetNameSpace('MAPI');     
    var mItm = objO.CreateItem(0);     
    mItm.Display();     
    mItm.To = p_recipient;
    mItm.Cc = p_cc;
    mItm.Subject = p_subject;
    mItm.Body = p_body;     
    mItm.GetInspector.WindowState = 2;
}

</script>

Tuesday, September 10, 2013

Embed image in a SharePoint outgoing email using SharePoint Designer workflow activities

If you need to embed an image into a SharePoint outgoing email:


<head>
<meta name="content-disposition" content="inline; filename=Myimage.jpg">
</head>

  • Format your email, and then to insert the image, create a div tag at the bottom of the email string:
<div style="text-align: center;">
<img src="Myimage.jpg" alt="myimagelogo" />
</div>

  • Add the action: Send Email with List Item Attachments
  • Attach the image in the activity, with the same name as used above (Myimage.jpg)
    • In mine, I always want to attach the same image in every outgoing email, so I uploaded an image to a SharePoint document library and I attached the image based on the specific title it contained
  • In the email body of the action, add the workflow variable: emailBody
  • Save, publish and test it out!