Search This Blog

Friday, March 16, 2012

Workflow

Intro:
This isa sample workflow , it ll send mail to a depends on a status,that status ismatained 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 inthat project)

You can find this workflow in soln explorer

And also you can find this in thatWorkflow1[Design]


Step3: By double click on thatevent(onWorkflowActivated1)you ll get invoked method for that you can writesome codings which are need to be done.at the time of workflow activated.
Step4:we can insert a condition (If-else)that’s placed attoolbox

Step5: you can write conditions with the property ofifElseActivity1&2
Properties-condition-codecondition-contion-“name of thatfunction”(ismailsenttoPM) it ll create a function in cs page,
Paste this coding in that function
private void ismailsenttoPM(objectsender, ConditionalEventArgs e)
{
getdata();
if(mailStatis == “Yes”)
{
e.Result = true;
}
else
{
e.Result = false;
}
}
private void getdata()
{
//GetUsername();
intid1 = Convert.ToInt16(workflowProperties.Item["ID"].ToString());
SPListobjList = workflowProperties.Web.Lists["Leave"];
SPListItemmyItem = 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 ifElseActivity1and write the code condition for that activity

code condition Name(sendmailtouser)
private void sendmailtouser(objectsender, EventArgs e)
{
SPSitespSite; 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(“”);
Body.Append(“

Dear PM,
”);
Body.Append(“I need Leave from “ + StartDate + ” To “ + EndDate + ”
”);
Body.Append(“for the Reason of” + Reason + “
”);
Body.Append(“URL:Click Here to see Approve orReject
”);
Body.Append(“
”);
Body.Append(“Sincerely,
”);
//Body.Append(“Administrator,
”);
Body.Append(“”+ Name + “
”);
SPUtility.SendEmail(spWeb, false,false, “test@test.com”,“Hi”, Body.ToString(), false);
}
}
});
}
Step7: create code conditions and code activity for theother branch.
Finally it shows likebelow image

Step8: deploy this for the desired list (it would haveoption for initiate at the time of item created and updated)
Step9: In your site you can find that workflow (in workflowsettings of that list)
Step10:add an item to that list (you ll be receiving maildepends on status of that item)

No comments:

Post a Comment