web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
New Discussion

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 509 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 375

#3
Adis Profile Picture

Adis 268 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans