Intro:
This is
a sample workflow , it ll send mail to a depends on a status,that status is
matained by a field of a list
Step1: Create a empty sharepoint project
Create a list in your sit with the following columns:
1. EmployeeName
2. StartDate
3. EndDate
4. PMStatus
5. MailPM
6. MailAdmin
7. AdminStatus
8. ReasonforLeave
Step2: Create a new Sequential workflow(by add new item in
that project)
You can find this workflow in soln explorer
And also you can find this in thatWorkflow1[Design]
Step3: By double click on that
event(onWorkflowActivated1)you ll get invoked method for that you can write
some codings which are need to be done.at the time of workflow activated.
Step4:we can insert a condition (If-else)that’s placed at
toolbox
Step5: you can write conditions with the property of
ifElseActivity1&2
Properties-condition-codecondition-contion-“name of that
function”(ismailsenttoPM) it ll create a function in cs page,
Paste this coding in that function
private void ismailsenttoPM(object
sender, ConditionalEventArgs e)
{
getdata();
if
(mailStatis == "Yes")
{
e.Result = true;
}
else
{
e.Result = false;
}
}
private void getdata()
{
//GetUsername();
int
id1 = Convert.ToInt16(workflowProperties.Item["ID"].ToString());
SPList
objList = workflowProperties.Web.Lists["Leave"];
SPListItem
myItem = workflowProperties.Web.Lists["Leave"].GetItemById(Convert.ToInt16(id1));
if
((int)myItem["ID"]
== id1)
{
id = Convert.ToInt16(myItem.ID);
Name = Convert.ToString(myItem["EmployeeName"]);
StartDate = Convert.ToString(myItem["StartDate"]);
EndDate = Convert.ToString(myItem["EndDate"]);
Status = Convert.ToString(myItem["PMStatus"]);
mailStatis = Convert.ToString(myItem["MailPM"]);
mailstatusadmin = Convert.ToString(myItem["MailAdmin"]);
adminappstatus = Convert.ToString(myItem["AdminStatus"]);
Reason = Convert.ToString(myItem["ReasonforLeave"]);
}
}
Step6: we can put a code activity in that ifElseActivity1
and write the code condition for that activity
code condition Name(sendmailtouser)
private void sendmailtouser(object
sender, EventArgs e)
{
SPSite
spSite; SPWeb spWeb; SPList spList;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using
(spSite = new SPSite("http://sp4:1"))
{
spSite.AllowUnsafeUpdates =
true;
using
(spWeb = spSite.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
StringBuilder Body = new StringBuilder("<table
cellpadding='3' cellspacing='0'
width='70%'>");
Body.Append("<tr><td><font face='verdana' size='2'>Dear PM, </font></td></tr>");
Body.Append("<tr><td nowrap><font face='verdana' size='2'>I need Leave from " + StartDate + " To " + EndDate + " </font></td></tr>");
Body.Append("<tr><td nowrap><font face='verdana' size='2'>for the Reason of
" + Reason + "
</font></td></tr>");
Body.Append("<tr><td>URL:<a
href='http://fpf:3344/Pages/NewPMStatus.aspx?ID=" + id + "'>Click Here</a> to see Approve or
Reject</td></tr>");
Body.Append("<tr><td> </td></tr>");
Body.Append("<tr><td><font face='verdana'
size='2'><b>Sincerely,</font></td></tr>");
//Body.Append("<tr><td><font face='verdana'
size='2'><b>Administrator,</font></td></tr>");
Body.Append("<tr><td><font face='verdana' size='2'><b>"
+ Name + "</font></td></tr>");
SPUtility.SendEmail(spWeb, false,
false, "ranjith@themajesticpeople.com",
"Hi", Body.ToString(), false);
}
}
});
}
Step7: create code conditions and code activity for the
other branch.
Finally it shows like
below image
Step8: deploy this for the desired list (it would have
option for initiate at the time of item created and updated)
Step9: In your site you can find that workflow (in workflow
settings of that list)
Step10:add an item to that list (you ll be receiving mail
depends on status of that item)







No comments:
Post a Comment