Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Time entry hour policy per day

(0) ShareShare
ReportReport
Posted on by 135

Project.Operation.Hani.Adel.Hours.Policy.zip

One of my customer ask me to restrict time entry hours per day, so user should not be able to add more than 8 hours per day when create time entry. I don't find any policy configuration can be used in Dynamics 365 CE project operation, so I decide to create my own custom workflow plugin that apply this request and I am glad to share it with you here.  

using System;
using System.Activities;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Workflow;

namespace Project.Operation.Hani.Adel.Hours.Policy
{
    public class HoursPolicy : CodeActivity
    {
        [Input("Owner ID")]
        [ReferenceTarget("systemuser")]
        public InArgument OwnerID { get; set; }

        [RequiredArgument]
        [Input("Date Entry")]
        public InArgument DateEntry { get; set; }

        [Output("Exceed or not")]
        public OutArgument Exceed { get; set; }

        protected override void Execute(CodeActivityContext executionContext)
        {
            IWorkflowContext context = executionContext.GetExtension();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension();
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            DateTime DFOR = DateEntry.Get(executionContext);
            DateTime AH2Date = DFOR.AddHours(3);
            string FormattedDate = AH2Date.Date.ToString("yyyy-MM-dd");

            Exceed.Set(executionContext, false);

            EntityReference ONRID = OwnerID.Get(executionContext);
            string ONRIDStr = ONRID.Id.ToString();

            string xml = ""  
                             ""  
                                          ""  
                                          ""  
                                         ""  
                                         ""  
                                     ""  
                             ""  
                         "";


            EntityCollection result = service.RetrieveMultiple(new FetchExpression(xml));
            Int32 rn = 0;
            foreach (var c in result.Entities)
            {
                Int32 totalCurrentYear = ((Int32)((AliasedValue)c["dursum"]).Value);
                rn  = totalCurrentYear;

            }

            if (rn > 481)
                Exceed.Set(executionContext, true);

        }
    }
}

I hope its help others developers.

hnno1982/Microsoft-Dynamics-365 (github.com)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,884 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,748 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans