Wednesday, December 31, 2008

Create a new sharepoint feature: Add a custom action to Task list item's drop down menu.

Normally, when we click on a sharepoint list item, from the drop down menu we can see: "View item, Edit item, Manage properties, Delete Item..." Lets see how can we add a new item to this drop down menu...

For my work, I need to add a custom action named "Change Status" to change the status of a Task list item. So, I modified the "EditForm.aspx" and created a new form named "ApproveStatus3.aspx" by using sharepoint designer. This page only edits the Status field of that item. Then I followed these steps:

1. Create a new folder, called "ChangeStatus", in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES
2. Create an empty Xml file, called "feature.xml" in the "ChangeStatus" folder or you can copy and paste the same "feature.xml" file from other feature folder
3. Empty the feature.xml file and add the following content

<?xml version="1.0" encoding="utf-8" ?>
<Feature Title="Change Status"
Description="Changes only the status of the leave letter."
Scope="Site"
Id="C0B8CB6D-6DD9-4c89-A1DC-E97A4745875C" xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="Elements.xml" />
</ElementManifests>
</Feature>

4. Create an empty Xml file, called "Elements.xml" in the "ChangeStatus" folder or you can copy and paste the same "feature.xml" file from other feature folder
5. Empty the file and add the following content


<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<CustomAction Id="ApprovalList.ChangeStatus"
RegistrationType="List"
RegistrationId="107"
Location="EditControlBlock"

Sequence="100"
Title="Change Status"

ImageUrl="/_layouts/images/TaskPane.gif">

<UrlAction Url="http://svradm002:11226/lms/Lists/ApprovalList/ApproveStatus3.aspx?ID={ItemId}&Source=http%3A%2F%2Fsvradm002%3A11226%2Flms%2FLists%2FApprovalList%2FMyItems%2Easpx" />
</CustomAction>
</Elements>

6. Run command prompt, and nevigate to sharepoint's BIN folder... cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN Press enter.
7. Install the new feature by running the following command:
Stsadm –o installfeature –name changestatus
8. Activate the new feature by running the following command:
Stsadm –o activatefeature -name changestatus -url
http://svradm002:11226/lms/

Here, registration id="107" menas this feature will be added with the drop down menu for items in task lists.

sequence="100" will probably place this item at the top most position of the drop down list. Increase the sequence number if you want to place it somewhere below.

in the url section,
http://svradm002:11226/lms/Lists/ApprovalList/ApproveStatus3.aspx? is the location where I saved my custorm editing form. ID={ItemId} passes the current item that has been clicked on. Source=http%3A%2F%2Fsvradm002%3A11226%2Flms%2FLists%2FApprovalList%2FMyItems%2Easpx holds the return address when the editing will be done. normally you can pass the address for "allitems.aspx" page from the browser's address box.




1 comment:

J said...

Okay, all I know is that if I google you and then go to the link to whatever post comes up in google, then I can comment you back.

I don't exactly remember what I said before but all I know is I want to be a print journalist. Photography is a passion of mine, but I'm not much of one.

And the 25th? Was that my really vague post? Ah well... Basically I was really down on myself because I was blaming myself for some problems between a couple of my friends--a foolish thought, but one that we all think at least once.