Saving Custom Task Form In Sharepoint Workflow

I have encountered a situation of saving the custom task form(Infopath) in workflow, the challenge here was to maintain the persistence of the data entered by the users, so that they can view the data saved when opened for the next time.

This is how i achieved it .

1. Add fields to be saved in ItemMetaData file .For eg if Comments is the field to be saved add this line in ItemMetaData file.

<z:row xmlns:z=”#RowsetSchema” ows_Comments_=””/>

2. Assign ows_Comments as the default value for the Comments fields. (check Secondary data source to assign).

3. Add Save Button .

4. Add rule to the button .(Add Submit connection and Submit data using the connection).

5. Add UpdateTask activity on completion of  OnTaskChanged in workflow.cs file.

6. Declare a variable called approverComments in workflow.cs source file .

7. Assign approverComments in onTaskChanged method,

if (On_Task_Changed_AfterProperties.ExtendedProperties[“Comments”] != null)
{
approverComments = On_Task_Changed_AfterProperties.ExtendedProperties[“Comments”].ToString();
}

This will get the Comments entered by the approver and assigns to a variable.

8. Add this line of code in UpdateTask activity.

this.Update_Task_TaskProperties = new SPWorkflowTaskProperties();
Update_Task_TaskProperties.ExtendedProperties[“ows_Comments”] = scpoShoppingCartNo;

This will assign the Comments entered by the approver to the Secondary Data Source we added in Step 1, that has been set the Default value for Comments field(Step 2). Now open the form to see the saved value .

Advertisements

Duplicate grouping in SPGRIDVIEW

I recommend one to read this blog if he/she is working on spgridview control.

I had a requirement of grouping the records in the grid based on a column, grouping is straight forward and can be achieved with just few lines of code.However, this used to generate duplicate grouping headers for the records in the grid.

 oSpGridView.AllowGrouping = true;
 oSpGridView.GroupField = “Status”;
 oSpGridView.GroupFieldDisplayName = “Status”;

I had to sort the records by columns (that is used for grouping) in the caml query before it is bound to the grid control.This is the line of code that did the trick for me.

 SPQuery oSortQuery = new SPQuery();

//Sorting by status.
 oQuery.Query = “<FieldRef Name=’Status’ Ascending=’True’ />”;
 SPListItemCollection oColl = oList.GetItems(oSortQuery);

We can then use the collection object to bind it to the grid control.

Create site from site template in sharepoint 2010

I was trying to create a site programatically based on the template that i have designed , i thought this should be straight forward and  passed the site template name as a parameter for the creation. Unfortunately, this wasn’t successful as the code was unable to recognize the site template name.

This blog speaks how to pass site template name as parameter.

Query Active directory for Username

I have been working on sharepoint-sap integration off late and have faced several challenges. One of those that i would like to share is extracting the windows account name from the firstname and lastname that you get it from SAP.

The windows account that you get from , can then be used to add users to the site. Enclosed is the snippet .

string strAdPath = “LDAP://dc=yourcompanyname,dc=com”;
string strUN= @”yourusername”;
string strPWD= “yourpassword”;
DirectoryEntry oLastEntry;
DirectoryEntry oFirstEntry;

public static DirectoryEntry GetDirectory()
{
DirectoryEntry oEntry = new DirectoryEntry(strAdPath ,strUN, strPWD, AuthenticationTypes.Secure);
return oEntry;
}

//Pass firstname and lastname to get the username

public string GetUserName(string firstName, string lastName)
{
DirectoryEntry oDirectoryEntry = GetDirectory();

DirectorySearcher oSearch = new DirectorySearcher(oDirectoryEntry);

//Search Criteria based on firstname
oSearch.Filter = “(&(objectClass=user)(givenName=” + firstName + “))”;

//Find all the records matching firstname
SearchResultCollection oResult = oSearch.FindAll();

//Loop through each records
foreach (SearchResult r in oResult)
{
oFirstEntry = r.GetDirectory();

//Check if the lastname of records retrieved matches with the lastname supplied
if ((string)oFirstEntry.Properties[“sn”].Value == lastName)
{
oLastEntry = r.GetDirectoryEntry();
}
}

//Get the username
if (oLastEntry != null)
{

userName = (string)userInfo.Properties[“samaccountname”].Value ?? string.Empty;
}

return userName;
}

Site templates in sharepoint 2010

The concept of Site template gallery and .STP file doesn’t exists in sharepoint 2010 anymore, rather they have replaced with Solution gallery and .wsp file respectively.

Save site as a template link disappears when the publishing feature is enabled and the work around seems to be navigating manually to /_layouts/Savetmpl.aspx. To have a look at the repository of the site templates we have to navigate to  Site Settings >Galleries >Solution Gallery.It can be noticed that our site would have saved with .wsp extension, that can be activated/deactivated like any other sandbox solution for usage.This on activation will be available for site creation. Thw .wsp[site template] file on click can also be downloaded as any other file and can be used as site template across web applications in sharepoint.

Hiding I Like it and Tag notes tags in Sharepoint 2010

I was customizing the master page in sharepoint 2010 and found out new tags and they were :

  • I Like it
  • Tags & notes

I had a requirement of hiding these tags in master page and hence, sharing the same in this blog.

  1. Open the site in IE 8.
  2. Press F12 to pop up the developer tools window.
  3. Arrow as shown below can be used to select any item in the page.
  4. This shows the section I like it and Tag & notes chosen.The tool shows the related HTML ,Scripts and styles with respect to the item.
  5. Now hide the section with styles using the tool editor as shown
  6. This tool however doesn’t make changes to the page, just gives us a preview of what has to be done.It is a nice tool that helps us in locating the items, classes and sneak peek at the changes.
  7. To make actual changes go to V4.Master and add the jQuery code to hide this . Register jQuery library in master pages before carrying out this operation .
  8. Now you can see that this section is disabled in the page.

5 mins on Jquery

This blog speaks about an overview on Jquery , it covers various questions on jQuery.

What is Jquery ?
Jquery is an improved version of Javascript, framework to build functions using javascript library.To build jquery applications download jQuery1.6.2 from here

Why to use Jquery ?
Jquery helps in rapid development and faster , concise as compared with javascript.

When to use Jquery ?
Jquery can be used on following ocassions
1.Animations,effects.
2.Attaching events to HTML elements.
3.Document traversing.
4.Ajax calls.
5.Dynamic CSS manipulations.

How to use ?
Jquery syntax is a combination of XPATH and CSS . The basic syntax looks like :

$(“HTML element”).event(function()
{
});

When not to use jQuery

1. When jQuery consumes plenty of client resources , it is not recommended to use jQuery. For instance : If we have 1000’s of items in a list, it is recommended to avoid jQuery as we have look through each items in the list.

2.jQuery can’t be used when there is no web service interface , for instance it can’t be used on workflows , event receivers .