Link to Email in InfoPath form


We all know how to create a link to an email in html page using the anchor tag. Do you know that the same is possible in InfoPath Form? Yes, we can do the same in infopath form in much simpler way. Here are the steps:

  • Consider the below Thank You Page(view) where we need to create a link to email for “Sathiya”

thank-you-page

  • Select the word and click on Insert->Hyperlink under Links section

insert-hyperlink

  • In Insert Hyperlink dialog box, type the email address as mailto:sathiya@abc.com in address box and click ok
  • When you preview the form, you will see Sathiya as an hyperlink which upon clicking opens outlook with To address as Sathiya

linking-with-outlook

Thats it!!!

Isn’t it much simpler? We are going to follow the same step when we need to add someone to CC, BCC just by replacing the address. Well, many of you may know how to change the email address for adding CC, BCC, subject and body, let me put them below to see everything at a single page.

To create email link with To and CC:

  • Replace the address as mailto:Sathiya@abc.com?cc=Rai@xyz.com

To create email link with To, CC and BCC:

  • Replace the address as mailto:Sathiya@abc.com?cc=Rai@xyz.com&bcc=Ganga@abc.com

To create email link with To and Subject:

  • mailto:Sathiya@abc.com?Subject=Form related queries

To create email link with To, Subject, CC and BCC:

  • mailto:Sathiya@abc.com?Subject=Form related queries&cc=rai@xyz.com&bcc=ganga@pqr.com

To create email link with many persons in To & CC and with subject:

  • mailto:Sathiya@abc.com;Jhansi@abc.com;Varun@abc.com?Subject=Queries&cc=Rai@xyz.com;amit@xyz.com

To create an email link with To, Subject, CC, BCC and body:

  • mailto:Sathiya@abc.com;Jhansi@abc.com?Subject=Queries&cc=Rai@xyz.com&bcc=ganga@xyz.com&body=Could you please answer the below queries

To create an email link with multiple lines in body:

  • mailto:Sathiya@abc.com?Subject=Queries&body=Hi Team, %0A Could you please clarify the below queries.

where %0A is linefeed (new line).

 
If you found it useful, please like and rate this!!

Comparing Dates in SharePoint


SCENARIO:

Let us assume that we need to hide some fields in SharePoint form based on other field value such as text box, what will we do? We will just check the value of the field on page load in edit form as shown below:

<script src="../Scripts/jquery.min.js"></script>
<script type="text/javascript"> 
$(document).ready(function()
{
if($("input[title='Title']").val()=="Text1") 
{
//hide fields
} 
});
</script>

This is pretty much simple. But assume that we need to hide some fields based on date and time value where Date and Time field is split into three controls:

  • Text box for Date along with Date Picker
  • Dropdown box to select Hours
  • Dropdown box to select Minutes

On seeing the three controls, we may think it is very complicated. Certainly not. We are going to achieve this by retrieving the id of date textbox and then append the id with the words, “Hours” and “Minutes” to get the value of Hours and Minutes dropdown. So, this will be quite interesting. Let’s start.

Retrieving value from Date and Time field:

The below code shows how to retrieve value from date and time field in edit form on page load. If we need to check the value of date and time field in new form on save button for some other requirement, use PreSaveAction function instead of document.ready function

<script src="../Scripts/jquery.min.js"></script>
<script type="text/javascript"> 
$(document).ready(function()
 {
 var startDate=getDateField("Start Date");//Display name of Date and Time field
 alert(startDate);
 });
 function getDateField(field)
 {
 var date = $(":input[title='" +field+ "']").val(); //retrieves date from date text box which is in mm/dd/yyyy format
 var d = new Date(date);
 var month =d.getMonth() + 1; //adding 1 as January starts at 0
 var day =d.getDate();
 var year = d.getFullYear();
//appending 0 for single digit date ad month
 if (month.length < 2) month = '0' + month; 
if (day.length < 2) day = '0' + day;
var dateID = $(":input[title='"+field+"']").attr("id");
var dateHours = $(":input[id='"+ dateID + "Hours" +"']").val();
var Meri=dateHours.split(' ')[1];
dateHours = dateHours.split(' ')[0];
//converting it into 24 hour format
 if(Meri == "PM" && dateHours<12)
    dateHours = parseInt(dateHours)+12;
 else if(Meri == "AM" && dateHours==12)
   dateHours = parseInt(dateHours)-12;
var dateMinutes=$(":input[id='"+dateID+"Minutes"+"']").val();
 var requiredDate=new Date(year,month-1,day,dateHours,dateMinutes,0);
 return requiredDate;
 }
</script>

To retrieve date and time in display form, use the below code:

<script src="../Scripts/jquery.min.js"></script>
<script type="text/javascript"> 
$(document).ready(function()
 {
var start = $.trim($('h3:contains("Start Date")').closest('td').next('td').text());
alert(start);
});
</script>

Comparing Current Date and time with Date in DateTime field:

After retrieving the value from Date and Time field, let’s say we need to check the current date and time and hide if current date is greater than Start Date field.

<script src="../Scripts/jquery.min.js"></script>
<script type="text/javascript"> 
$(document).ready(function()
 {
 var startDate=getDateField("Start Date");//Display name of Date and Time field
 var current=new Date();
 if(current>=startDate)
 {
 //hide fields
 }
 });
 function getDateField(field)
 {
var date = $(":input[title='" +field+ "']").val(); //retrieves date from date text box which is in mm/dd/yyyy format
var d = new Date(date);
var month =d.getMonth() + 1; //adding 1 as January starts at 0
var day =d.getDate();
var year = d.getFullYear();
//appending 0 for single digit date ad month
 if (month.length < 2) month = '0' + month; 
if (day.length < 2) day = '0' + day;
var dateID = $(":input[title='"+field+"']").attr("id");
var dateHours = $(":input[id='"+ dateID + "Hours" +"']").val();
var Meri=dateHours.split(' ')[1];
dateHours = dateHours.split(' ')[0];
//converting it into 24 hour format
 if(Meri == "PM" && dateHours<12)
    dateHours = parseInt(dateHours)+12;
 else if(Meri == "AM" && dateHours==12)
   dateHours = parseInt(dateHours)-12;
var dateMinutes=$(":input[id='"+dateID+"Minutes"+"']").val();
var requiredDate=new Date(year,month-1,day,dateHours,dateMinutes,0);
 return requiredDate;
 }
</script>

To compare two SharePoint date fields, we need to call getDateField function for both the dates as:

<script src="../Scripts/jquery.min.js"></script>
<script type="text/javascript"> 
$(document).ready(function()
 {
var startDate=getDateField("Start Date");//Display name of Date and Time field
var EndDate=getDateField("End Date");
 if(EndDate<=startDate)
 {
 alert("End Date should be greater than Start Date)
 }
 });
</script>

Hiding fields before three hours of start date in SharePoint

To hide the fields from three hours prior to start Date  time, lets subtract three hours from Start Date time and then compare with current date and time as shown below:

<script src="../Scripts/jquery.min.js"></script>
<script type="text/javascript"> 
$(document).ready(function()
 {
 var startDate=getDateField("Start Date");//Display name of Date and Time field
 var current=new Date();
 var subbed = new Date(startDate - 3*60*60*1000); // subtract 3 hours
 if(current>=subbed)
 {
 //hide fields
 }
});
function getDateField(field)
 {
var date = $(":input[title='" +field+ "']").val(); //retrieves date from date text box which is in mm/dd/yyyy format
var d = new Date(date);
var month =d.getMonth() + 1; //adding 1 as January starts at 0
var day =d.getDate();
var year = d.getFullYear();
//appending 0 for single digit date ad month
 if (month.length < 2) month = '0' + month; 
if (day.length < 2) day = '0' + day;
var dateID = $(":input[title='"+field+"']").attr("id");
var dateHours = $(":input[id='"+ dateID + "Hours" +"']").val();
var Meri=dateHours.split(' ')[1];
dateHours = dateHours.split(' ')[0];
//converting it into 24 hour format
 if(Meri == "PM" && dateHours<12)
    dateHours = parseInt(dateHours)+12;
 else if(Meri == "AM" && dateHours==12)
   dateHours = parseInt(dateHours)-12;
var dateMinutes=$(":input[id='"+dateID+"Minutes"+"']").val();
var requiredDate=new Date(year,month-1,day,dateHours,dateMinutes,0);
 return requiredDate;
 }
</script>

Please do not forget to like or rate the article 😛