web
You’re offline. This is a read only version of the page.
close
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)

I have the same question (0)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 503 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 434 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans