Friday, February 22, 2013

Project Server - People picker

When user customizes Project Detail Pages in Project Server, he can add many Custom Fields to one page. He can choose from six types of Custom Fields: Cost, Date, Duration, Flag, Number, Text. That is good, but it isn't enough. Where is "People picker" field type?


If you open Project Detail Page called Project Information, you can see default field for Owner. It is a people picker field:




Well, if this field type exists on default Project Server Pages, how come it can not be added to customized page?

I actually don't know the answer to that question, but it is a fact that you can not add this field type to your page.

But, there is another solution. People picker for Project Server exists in another form. In some of my previous posts, I mentioned Solution Starters package from Microsoft (when I talked about Dynamic Workflow).

In this package, you can find solution for people picker field, it is called PDPCustomization.

If you want to use people picker field in your forms, first you need to download Solution Starters package from this link:
http://archive.msdn.microsoft.com/P2010SolutionStarter

EDIT (8.6.2014.)
Microsoft has retired link for downloading this solution, so for downloading Solution Starters go to these links depending on the version of Project Server you are using:
Project Server 2010:
https://drive.google.com/file/d/0Bz62Vp3ZwGCrRDBCdjNrYUNYWmM/edit?usp=sharing
Project Server 2013:
http://www.fluentpro.com/solutionstarters2013.html 

Look for PDPCustomization.zip file in that package, extract it and deploy solution to your Project Server.

After the solution is deployed, to add a people picker to the page, web part of deployed solution must be added to the page. Web Part is called AutoComplete Web Part and it is located in PDP Customization folder:







Position this new AutoComplete Web Part under the existing Web Part on the page.
Click on Edit Web Part on the Web Part menu. Menu with properties of that Web Part will open. In that menu, you can choose the group from which users will be fetched and field name in which the name of this user will be saved (this field is Custom Field of type "Text").



After the changes have been saved, your custom field will now read users from Administrators group.




Tuesday, February 19, 2013

Sharepoint 2010 - Set value in textbox in SP forms with jQuery

Putting values in html textboxes is not as easy in SharePoint forms as it is in a regular html forms.It isn't difficult, but it takes a while to figure it out.

In ordinary html form, if you define your textbox like this:

<input type="text" id="txt1">

then you can set value in that textbox with javascript like this:

<script>
window.onload=function(){
        var txt1 = document.getElementById("txt1");
        txt1.value = "MyText";
};
</script>

Well, with SharePoint, things aren't exactly the same. In SharePoint form, you can't just get element by its id, because you can't read its id, because it is server-generated. Actually, you can read it, but only after you load the page in browser, and you will find out that it is a very long guid.It is not recommendable to access elements using this id.

So, if you open your form in SharePoint Designer, you can see how table rows are defined in html. For examlpe, here is the row of form's "Title" element:





 You can see here that your textbox has id="ff1{$Pos}".

If you want to read that element and put some value in it, then you can do the following:

1. Give that row an ID (for example: id="myRow").



2. Now, in javascript, you can do this (jQuery library must be included on the page):

<script>
window.onload=function(){
        var spRow = document.getElementById("myRow");
        var spInput = element.getElementsByTagName("input")[0];
        spInput.value = "SomeValue";

};
</script>

And text "SomeValue" will appear in your form, in field "Title" when the page loads.

Friday, February 15, 2013

Project Server - Workflow approval email: Approval required for project: '... has been assigned to you

The full potential of Project Server is realized only when a powerful workflow solution is deployed along with it. One of the best workflow solutions is Solution Starters Dynamic Workflow (and it is free), which I mentioned in on of my previous posts.

Dynamic Workflow is great solution, but, it has many faults as well. One of them are email notifications to users who have workflow tasks assigned to them (approvers).

When project is send to approval, all tasks for all users are stored in SharePoint list called Project Server Workflow Tasks, and in that moment email notification is send to users who are approvers for that task.

This how this email looks like:




The problem is in its subject:

Project Server Workflow Tasks - Approval required for project: '... has been assigned to you

 In subject (or anywhere else in email) user can not see the name of the project, so user does not know what project he must approve/reject.

I have searched for the solution of this problem, but without success. These notifications are SharePoint generated emails, and subject of the email and the body are generated from series of XML definitions from SharePoint XML files (file is called alertemplates.xml and it is located in
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML

But, modifying this XML file is not recommendable, because all list on entire farm are using it, and it is also complicated to find what you need to change in order to get the desired results. I my next post, I will describe how to make your custom alert template XML file.

So, I've come up with a different solution. Solution is to turn off email notifications for this SharePoint list and to build a custom event receiver for that list which will send its own notifications with content that you desire:

SOLUTION:

1. Go to SharePoint list "Project Server Workflow Tasks":
     Site Actions --> Site Settings --> Site libraries and lists (in Site Administration) --> Customize Project Server Workflow Tasks
2. Click on Advanced settings in section General Settings.
3. In section E-mail Notification, select option "No" for Send e-mail when ownership is assigned option.

4. Now it is time to open Visual Studio 2010 and build your event handler.

NOTE: Building an event handler for this particular list is not straight forward, but it can be found on blogs, so I will not go in detail here. If someone needs help with this part, leave a comment, and will try to help.

5. After the event handler has been made, System.Net.Mail library can be used for sending mail form code. Created new class and create following class in it. In it, you can read task title, owner of the task, approver, etc from SharePoint list. Here is the code:


class ProjectWorkflowEvent: SPItemEventReceiver
{
     public override void ItemAdded(SPItemEventProperties properties)
     {
           base.ItemUpdated(properties);
          
           //reading title value from Project Server Workflow Tasks list
           string _title = properties.ListItem["Title"].ToString();
           string _decision = properties.ListItem["Outcome"].ToString();
            
           SPFieldLookupValue _assignedTo = new SPFieldLookupValue(properties.ListItem["Assigned      To"].ToString());
           string _assignedName = _assignedTo.LookupValue;

           SPSite oSiteCollection = new SPSite(properties.WebUrl);
              
           string _userMail = "";

           using (SPWeb oWebSite = oSiteCollection.OpenWeb())
           {
                 //read user email address
                 SPUser oUser = oWebSite.EnsureUser(_assignedName);
                 _userMail = oUser.Email;
            }

            //send email  
            string smtpServer =    SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address;
            string smtpFrom = SPAdministrationWebApplication.Local.OutboundMailSenderAddress;

           //Create the mail message and supply it with from and to info
           MailMessage mailMessage = new MailMessage(from@address.com, to@address.com);

           //Set the subject and body of the message
           mailMessage.Subject = "Approval required for project: '" + _title + "' has been assigned to you";
           mailMessage.Body = "My custom body";
                  
         
           //Create the SMTP client object and send the message
           SmtpClient smtpClient = new SmtpClient(smtpServer);
           smtpClient.Send(mailMessage);
      }
}

Now, your email can look something like this (or what ever you like):