Showing posts with label Workflow. Show all posts
Showing posts with label Workflow. Show all posts

April 11, 2012

Worflow - New Request Mail

Step 1:File ->New -> Project ->Sharepoint 2010 ->Sequential Workflow

































Step 2:Add references to Workflow project Ex Microsof.Office.Server

Step 3: Drag and Drop the Logtohistory control in workflow.cs


















Step 4: Copy paste the below methods in Sendmail _Invoked Function

private void Sendmail_Invoked(object sender, ExternalDataEventArgs e)

{
          string user = workflowProperties.OriginatorUser.LoginName;

string domain = Convert.ToString(user.Split('\\').GetValue(0));

if (domain.Contains("|"))

{

domain =   Convert.ToString(domain.Split('|').GetValue(1));
}         
string loginname = "";           
SPServiceContext context = SPServiceContext.GetContext(workflowProperties.Site);
          UserProfileManager upm = new UserProfileManager(context);

int ListItemID = System.Convert.ToInt32(workflowProperties.ItemId);

#region Approved mail       

//if managerstatus approved - send to mail Groupmanager

if (Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Manager Status"]) == "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["GMStatus"]) != "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["CEOStatus"]) != "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["L And TStatus"]) != "Approved")

{UserProfile profile = upm.GetUserProfile(Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["GroupManager"]));
               
String WorkEmail = profile[PropertyConstants.WorkEmail].Value.ToString();
SendMail(Convert.ToString(profile[PropertyConstants.WorkEmail].Value), Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Login Name"]), Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["GroupManager"]), "Approved");

}else if (Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Manager Status"]) == "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["GMStatus"]) == "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["CEOStatus"]) != "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["L And TStatus"]) != "Approved")

{                UserProfile profile = upm.GetUserProfile(Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["CEO"]));
               
String WorkEmail = profile[PropertyConstants.WorkEmail].Value.ToString();

SendMail(Convert.ToString(profile[PropertyConstants.WorkEmail].Value), Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Login Name"]), Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["CEO"]), "Approved");
}
          
else if (Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Manager Status"]) == "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["GMStatus"]) == "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["CEOStatus"]) == "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["L And TStatus"]) != "Approved")

{             UserProfile profile = upm.GetUserProfile(Convert.ToString((workflowProperties.List.Items.GetItemById(ListItemID)["L_and_T"])));
        String WorkEmail = profile[PropertyConstants.WorkEmail].Value.ToString();

SendMail(Convert.ToString(profile[PropertyConstants.WorkEmail].Value), Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Login Name"]), Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["L_and_T"]), "Approved");}

else if (Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Manager Status"]) == "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["GMStatus"]) == "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Travel Destination"]) == "Inter-State")

{                UserProfile profile = upm.GetUserProfile(Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["L_and_T"]));

SendMail(Convert.ToString(profile[PropertyConstants.WorkEmail].Value), Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Login Name"]), Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["L_and_T"]), "Approved");
}
#endregion

#region Rejected mail
//if managerstatus reject - send to mail Accountname(who is request send to him)
          
else if (Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Manager Status"]) == "Reject" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["GMStatus"]) != "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["CEOStatus"]) != "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["L And TStatus"]) != "Approved")

{

loginname = domain + "\\" + Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Login Name"]);UserProfile profile = upm.GetUserProfile(loginname);
String WorkEmail = profile[PropertyConstants.WorkEmail].Value.ToString();
SendMail(Convert.ToString(profile[PropertyConstants.WorkEmail].Value), Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Login Name"]), Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["ManagerName"]), "reject");}

//if managerstatus approved,GMStatus reject - send to mail Accountname(who is request send to him)

else if (Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Manager Status"]) == "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["GMStatus"]) == "Reject" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["CEOStatus"]) != "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["L And TStatus"]) != "Approved")

{

loginname = domain +"\\" + Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Login Name"]);
UserProfile profile = upm.GetUserProfile(loginname);

String WorkEmail = profile[PropertyConstants.WorkEmail].Value.ToString();

SendMail(Convert.ToString(profile[PropertyConstants.WorkEmail].Value), Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Login Name"]), Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["GroupManager"]), "reject");}        
//if managerstatus-GMStatus=approved,CEOStatus-reject - send to mail Accountname(who is request send to him)

else if (Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Manager Status"]) == "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["GMStatus"]) == "Approved" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["CEOStatus"]) == "Reject" && Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["L And TStatus"]) != "Approved")

{

loginname = domain +
"\\" + Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Login Name"]);

UserProfile profile = upm.GetUserProfile(loginname);

String WorkEmail = profile[PropertyConstants.WorkEmail].Value.ToString();

SendMail(Convert.ToString(profile[PropertyConstants.WorkEmail].Value), Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Login Name"]), Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["CEO"]), "reject");}

#endregion
else

{UserProfile profile = upm.GetUserProfile(Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["ManagerName"]));

SendMail(Convert.ToString(profile[PropertyConstants.WorkEmail].Value), Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["Login Name"]), Convert.ToString(workflowProperties.List.Items.GetItemById(ListItemID)["ManagerName"]), "Approved");

}

}
       public bool SendMail(string ToEmail, string username, string managername, string status)
{    
return SPUtility.SendEmail(workflowProperties.Web,true, false, ToEmail, "External Course and Conference Request Form", MailContent(username, managername, status));

}public string MailContent(string username, string managername,string status)

{StringBuilder sBuilder = new StringBuilder();
          
if (status == "Approved")

{

sBuilder.Append("<table width='100%' border='0' cellspacing='0' cellpadding='0' style='border:3px solid #ebebeb; padding:5px; background-color:#fbfbfb;'>");
sBuilder.Append("<tr><td colspan='2' style='font-family:Arial, Helvetica, sans-serif; font-size:18px; color:#036; padding:10px; border-bottom:1px dotted #ccc; font-weight:bold;'>New External Course and Conference Request Mail</td></tr>");

sBuilder.Append("<tr><td style='font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#990000; padding:10px; text-align:Left'>Hi,</td>");
sBuilder.Append("<tr><td style='font-family:Arial, Helvetica, sans-serif; font-weight=bold; font-size:13px; color:#990000; padding:10px; text-align:right'>" + DateTime.Now.ToShortDateString() + "</td></tr>");sBuilder.Append("<tr><td colspan='2' style='font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#333; padding:10px; text-align:justify'> &nbsp;&nbsp;&nbsp;&nbsp; Your Request has been Approved by<b> " + managername + "</b> </td></tr>");
sBuilder.Append("<tr><td colspan='2' style='font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#333; padding:10px;'>Thank You <br /><a href='" + workflowProperties.SiteUrl + "/New%20External%20Course%20and%20Conference%20Request%20Form/Forms/AllItems.aspx" + "'>Click here</a> for details </td></tr>");sBuilder.Append("<tr><td colspan='2' style='font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#333; padding:10px;'><table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td style='padding:10px; background-color: #9CF; font-style:italic'>Note: This E-mail is for Notification Purpose only, <strong>DO NOT Reply to this email</strong></td></tr></table></td></tr>");s
Builder.Append("</table>");

}else

{

sBuilder.Append("<table width='100%' border='0' cellspacing='0' cellpadding='0' style='border:3px solid #ebebeb; padding:5px; background-color:#fbfbfb;'>");
sBuilder.Append("<tr><td colspan='2' style='font-family:Arial, Helvetica, sans-serif; font-size:18px; color:#036; padding:10px; border-bottom:1px dotted #ccc; font-weight:bold;'>New External Course and Conference Request Mail</td></tr>");

sBuilder.Append("<tr><td style='font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#990000; padding:10px; text-align:Left'>Hi,</td>");sBuilder.Append("<td style='font-family:Arial, Helvetica, sans-serif; font-weight=bold; font-size:13px; color:#990000; padding:10px; text-align:right'>" + DateTime.Now.ToShortDateString() + "</td></tr>");

sBuilder.Append("<tr><td colspan='2' style='font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#333; padding:10px; text-align:justify'> &nbsp;&nbsp;&nbsp;&nbsp;Your Request has been Rejected by<b>" + managername + "</b></td></tr>");sBuilder.Append("<tr><td colspan='2' style='font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#333; padding:10px;'>Thank You <br /><a href='" + workflowProperties.SiteUrl + "/New%20External%20Course%20and%20Conference%20Request%20Form/Forms/AllItems.aspx" + "'>Click here</a> for details </td></tr>");

sBuilder.Append("<tr><td colspan='2' style='font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#333; padding:10px;'><table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td style='padding:10px; background-color: #9CF; font-style:italic'>Note: This E-mail is for Notification Purpose only, <strong>DO NOT Reply to this email</strong></td></tr></table></td></tr>");
sBuilder.Append("</table>");}
          
return sBuilder.ToString();

}

March 19, 2012

Workflow
















Click on the Workflow Activated and paste this below coding in that function.
 private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e) 
 { 
 StringDictionary headers = new StringDictionary(); 
 headers.Add("to", "vidhya@themajesticpeople.com");
 headers.Add("from", "avidhume@gmail.com");
 headers.Add("sub", "Test mail");
//SPUtility.SendEmail(workflowProperties.Web,false,false,"avidhume@gmail.com", "Hello World", "This is a Sample Mail"); 
 SPUtility.SendEmail(workflowProperties.Web, headers, "hi hw r u");
 }

March 05, 2012

Workflow

Workflow

 The process that defines and controls the completion of one or more tasks in order to bring about the realization of an identified goal.

Types of Workflow:

* Workflows fall into one of two broad types, based on how the tasks are processed:

* Sequential workflows:

o Typically depicted as a flowchart, in which the process has a beginning, a prescribed path (which could include parallel branches, criteria-based branching, and loops, but is nonetheless a defined path) and an end.

o Out-of-the-box workflows and workflows created in the designer are sequential workflows.

o A sequential workflow works very well in many scenarios you are likely to encounter when implementing Workflow in Office 2007:

# Approval

# Translation

# Feedback


 Collaboration



Creating SharePoint 2010 Workflows: Starting with Visual Studio 2010 Part 3

Go to the Expense Reports list. Select the expense report that you created earlier, and then click the Workflows button on the SharePoint Ribbon, as Figure 23 shows. The Start a New Workflow window, which Figure 24 shows, appears.

Click the Workflow button to start our workflow. Go to the workflow status, and you should see the Hello World message, as Figure 25 shows.


Figure 23: Choosing a workflow in the SharePoint Ribbon


Figure 24: Starting a workflow



Figure 25: Workflow outcome with Hello World


Workflow Features


Workflows that are generated from VS 2010 are logically packaged as site collection features. If the feature is not activated, then the workflow template cannot be used.
Workflows that are generated by VS 2010 are compiled as .dll files that must be installed into the global assembly cache (GAC). Therefore, these kinds of workflows cannot run in the sandbox environment, even if we create custom sandbox activities (as I will illustrate in another article).
If you look at the elements.xml file that describes the workflow feature (Figure 26), you will find the <Workflow> element, which points to the workflow class Name, as well as the placeholder for the assembly name.
New in SharePoint 2010 is the <AssociationCategories> element, which can contain List (if the workflow must be associated with a SharePoint list), Site (if the workflow must be associated with a SharePoint site), or Content Type (if the workflow is associated with a content type, which is an excellent practice).
The <StatusPageUrl> element specifies the .aspx page that is used to display the workflow status. I usually keep the default _layouts/WrkStat.aspx, but you can replace it with a custom page if needed.


Figure 26: Workflow element.xml file

Wizard Setting Configuration


If you want to modify the settings that the VS 2010 SharePoint Configuration Wizard provides, then you can select the workflow SharePoint project item, display its property page (which Figure 27 shows), and change the settings. For instance, you can change the Task List, or you can cancel the automatic association of the workflow with the list (via the Auto Associate property).
If you try to modify the task list, a new SharePoint Customization Wizard window will appear, as Figure 28 shows.


Figure 27: Workflow settings provided by the wizard



Figure 28: Triggering the wizard

Reviewing the Code


If you open the file ExpenseReportWorkflow.cs, you will see a class that is derived from SequentialWorkflowActivity (see Figure 29), which is the root class for Sequential workflows. (There are two kinds of workflows: Sequential and State Machine, which I will illustrate in another article.)
If you open the Designer code, you will see that each activity is a member of this class, which Figure 30 shows.
In the next article of this series, we will enhance this workflow.


Figure 29: Deriving a class from SequentialWorkflowActivity

Creating SharePoint 2010 Workflows: Starting with Visual Studio 2010 Part 2

Building and Deploying



Go to the Build menu and select Deploy Solution. This generated code is called a workflow template; several instances of the same workflow template can be associated to the same list or to a different list in the site collection.


Go to your site, click the Expense Reports list, go to the list settings, and click the Workflow Settings button on the SharePoint Ribbon, as Figure 13 shows.


Figure 13: Workflow button
The Workflow Settings window appears. This window shows a list of available workflow templates. Our workflow template is available because it is encapsulated in a SharePoint feature with a scope of Site (a site collection); more about this later.
In this window, you can associate your workflow template with the current list.
We already have one association (performed by VS 2010), named Litware, as Figure 14 shows.ExpenseReports-ExpenseReportWorkflow, but you can create other workflow associations by clicking the Add a workflow hyperlink. (You can display the list of available workflow templates by clicking the drop-down arrow.)
Click the Litware.ExpenseReports-ExpenseReportWorkflow association link to view the workflow association settings, which Figure 15 shows. Note that the option is selected to start the workflow when a new item is created. Click OK.

Figure 14: Workflow association

Figure 15: Workflow association settings

Go to the Expense Report list and add a new item, as Figure 16 shows. Save this item. Because the workflow is configured to start when a new item is created, saving the item will cause a workflow instance to be created from our workflow template.


Figure 16: Adding a new list item
Indeed, if you go back to the list view, which Figure 17 shows, you will notice a new column that has the workflow association as a name. If you click the Completed hyperlink, you will visualize the workflow status, history, and tasks in the Workflow Information window, which Figure 18 shows.



Figure 17: Workflow Association column




Figure 18: Workflow Information window


Using Workflow Activities

A workflow is a set of steps; each step is an activity. Activities are .NET classes. We can reuse existing activities or create custom activities, as I will illustrate later.
The Workflow Foundation (WF) infrastructure is a set of assemblies that can be visualized in the References folder of our VS 2010 project (see Figure 19).
As part of the .NET Framework 3.5, WF provides several interesting activities that can be used in SharePoint. (Not all WF activities can be used in SharePoint, however.)
These activities are provided in the System.Workflow.Activities assembly, as Figure 19 shows.


Figure 19: Workflow assemblies to reference
The SharePoint team also provided more specific SharePoint activities, which you can find in the Microsoft.SharePoint.WorkflowActions assembly. This assembly can be found in the 14\ISAPI folder and is referenced by default in our VS 2010 project.
These activities can be dragged and dropped into the VS workflow design surface from the toolbox (select the SharePoint Workflow panel), which Figure 20 shows.


Figure 20: Workflow activities toolboxes




Just to make sure that our basic workflow can at least say "Hello World," we will drag and drop LogToHistoryListActivity to the workflow surface. Figure 21 shows the addition of an activity.
Now, in Workflow Designer, select logToHistoryActivity, go to its property page, and type "Hello World" in the HistoryOutcome property, as Figure 22 shows. Deploy the solution as you did previously (selecting Deploy Solution from the Build menu).



Figure 21: Adding an activity




Figure 22: LogToHistoryList activity properties

Go to the Expense Reports list. Select the expense report that you created earlier, and then click the Workflows button on the SharePoint Ribbon, as Figure 23 shows. The Start a New Workflow window, which Figure 24 shows, appears.
Click the Workflow button to start our workflow. Go to the workflow status, and you should see the Hello World message, as Figure 25 shows