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.