Approve and Reject Task using PSI Project Server 2013

Approve and Reject Task using PSI Project Server 2013

Approve and Reject Task using PSI Project Server 2013. Timesheet Manager when login and go on approval center then he will see there are multiple tasks in approval center. He can Approve and Reject task or can edit Task according to the project plan. He can Approve and Reject task manually or by custom code. Below is code for Approve and Reject Task using PSI Project Server 2013:-

Below is image shown the needed namespace:-

Approve and Reject Task

If you don’t know how to create project server service DLL then follow my previous post:-

How to create ProjectServerService.dll [AdSense-A]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Threading.Tasks;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace Approve_Reject_Task
{
    class Program
    {
        static Guid CurrentUserUID = Guid.Empty;
       static string ASSNUID = string.Empty;
       private static SvcStatusing.StatusingClient statusingClient;
       static SvcResource.ResourceClient resourceClient;
       public static string PWAUrl = "http://serverName/PWApath"; 
        static string CurrentUser = "donald"; //current login name;
         
        static void Main(string[] args)
        {
            TaskApproval();
            TaskReject();
        }
        public static void TaskApproval()
        {

            CurrentUser = string.Concat("i:0#.w|DomainName", @"\", CurrentUser);
            
            try
            {
                SvcResource.ResourceDataSet ResourceDS = new SvcResource.ResourceDataSet();
                SvcStatusing.StatusApprovalDataSet statusdataset = new SvcStatusing.StatusApprovalDataSet();
                SetClientEndpoint(PWAUrl);
                ResourceDS = resourceClient.ReadResources("", false);
                CurrentUserUID = new Guid(ResourceDS.Resources.Select("WRES_ACCOUNT='" + CurrentUser + "'").Length > 0 ? ResourceDS.Resources.Select("WRES_ACCOUNT='" + CurrentUser + "'")[0][ResourceDS.Resources.RES_UIDColumn].ToString() : "00000000-0000-0000-0000-000000000000");
                PSLibrary.PSContextInfo contextInfo = new PSLibrary.PSContextInfo(true, CurrentUser, CurrentUserUID, Guid.Empty, Guid.Empty, null, null);
                string contextInfoString = PSLibrary.PSContextInfo.SerializeToString(contextInfo);
                using (OperationContextScope scope = new OperationContextScope(statusingClient.InnerChannel))
                {
                    
                    WebOperationContext.Current.OutgoingRequest.Headers.Remove("PjAuth");
                    WebOperationContext.Current.OutgoingRequest.Headers.Add("PjAuth", contextInfoString);
                    // Disable Forms authentication, to enable Windows authentication.
                    WebOperationContext.Current.OutgoingRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");

                    statusdataset = statusingClient.ReadStatusApprovalsSubmitted(false);

                    if (statusdataset.StatusApprovals.Select("ASSN_UID='" + ASSNUID + "'").Length > 0)
                    {
                        statusdataset.StatusApprovals.Select("ASSN_UID='" + ASSNUID + "'")[0][statusdataset.StatusApprovals.ASSN_TRANS_ACTION_ENUMColumn] = (int)PSLibrary.TaskManagement.StatusApprovalType.Accepted;
                        statusingClient.UpdateStatusApprovals(statusdataset);
                        statusingClient.QueueApplyStatusApprovals(new Guid(), string.IsNullOrEmpty("txtComments.Text") ? string.Empty : "txtComments.Text");
                    }

                }


            }

            catch (Exception ex)
            {

            }

        }
        public static void TaskReject()
        {

            CurrentUser = string.Concat("i:0#.w|DomainName", @"\", CurrentUser);
            
            SvcResource.ResourceDataSet ResourceDS = new SvcResource.ResourceDataSet();
            SvcStatusing.StatusApprovalDataSet statusdataset = new SvcStatusing.StatusApprovalDataSet();
         
            SetClientEndpoint(PWAUrl);
            
                ResourceDS = resourceClient.ReadResources("", false);


                CurrentUserUID = new Guid(ResourceDS.Resources.Select("WRES_ACCOUNT='" + CurrentUser + "'").Length > 0 ? ResourceDS.Resources.Select("WRES_ACCOUNT='" + CurrentUser + "'")[0][ResourceDS.Resources.RES_UIDColumn].ToString() : "00000000-0000-0000-0000-000000000000");

                PSLibrary.PSContextInfo contextInfo = new PSLibrary.PSContextInfo(true, CurrentUser, CurrentUserUID, Guid.Empty, Guid.Empty, null, null);
                string contextInfoString = PSLibrary.PSContextInfo.SerializeToString(contextInfo);

                using (OperationContextScope scope = new OperationContextScope(statusingClient.InnerChannel))
                {
                    
                    WebOperationContext.Current.OutgoingRequest.Headers.Remove("PjAuth");
                    WebOperationContext.Current.OutgoingRequest.Headers.Add("PjAuth", contextInfoString);
                    // Disable Forms authentication, to enable Windows authentication.
                    WebOperationContext.Current.OutgoingRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");

                    statusdataset = statusingClient.ReadStatusApprovalsSubmitted(false);
                    
                        if (statusdataset.StatusApprovals.Select("ASSN_UID='" + ASSNUID + "'").Length > 0)
                        {

                            statusdataset.StatusApprovals.Select("ASSN_UID='" + ASSNUID + "'")[0][statusdataset.StatusApprovals.ASSN_TRANS_ACTION_ENUMColumn] = (int)PSLibrary.TaskManagement.StatusApprovalType.Rejected;
                            statusingClient.UpdateStatusApprovals(statusdataset);
                            statusingClient.QueueApplyStatusApprovals(new Guid(), string.IsNullOrEmpty("txtComments.Text") ? string.Empty : "txtComments.Text");
                           
                        }
                    }
        
        }
       

    }
}

 


Comments

  1. Seriously incredibly amazing web site. Fairly pleasant towards browse and fairly substantially appealing written content. Unquestionably year has not nevertheless arrive again and greet.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!