internal void CanNavigateForwardHandler(ICDSPluginExecutionContext executionContext) { var req = executionContext.CreateOrganizationRequest <ccllc_BTF_CanNavigateForwardRequest>(); EntityReference transactionId = req.Target ?? throw new NullReferenceException("Target cannot be null"); EntityReference userId = req.UserId ?? new EntityReference("systemuser", executionContext.InitiatingUserId); var systemUser = new SystemUser(userId.LogicalName, userId.Id, userId.Name); var platformService = Container.Resolve <IPlatformService>(); var session = platformService.GenerateSession(executionContext, systemUser); var managerFactory = Container.Resolve <ITransactionServiceFactory>(); var manager = managerFactory.CreateTransactionService(executionContext); var transaction = manager.LoadTransaction(executionContext, transactionId.ToRecordPointer()); bool canNavigate = transaction.CanNavigateForward(session); executionContext.OutputParameters["IsAllowed"] = canNavigate; }
internal void NavigateBackwardHandler(ICDSPluginExecutionContext executionContext) { var req = executionContext.CreateOrganizationRequest <ccllc_BTF_NavigateBackwardRequest>(); EntityReference transactionId = req.Target ?? throw new NullReferenceException("Target cannot be null"); EntityReference userId = req.UserId ?? new EntityReference("systemuser", executionContext.InitiatingUserId); var systemUser = new SystemUser(userId.LogicalName, userId.Id, userId.Name); var platformService = Container.Resolve <IPlatformService>(); var session = platformService.GenerateSession(executionContext, systemUser); var managerFactory = Container.Resolve <ITransactionServiceFactory>(); var manager = managerFactory.CreateTransactionService(executionContext); var transaction = manager.LoadTransaction(executionContext, transactionId.ToRecordPointer()); IUIPointer uiPointer = null; var step = transaction.NavigateBackward(session); if (step.Type.IsUIStep) { uiPointer = step.GetUIPointer(executionContext, transaction); } if (uiPointer == null) { // At this point something is wrong so navigate the user to the transaction error form. uiPointer = new UIPointer { UIDefinition = "TransactionError", UIRecordId = transaction.Id, UIRecordType = "ccllc_transaction", UIType = eUIStepTypeEnum.DataForm }; } executionContext.OutputParameters["UIPointer"] = uiPointer.Serialize(); }
internal void GetAvailableTransactionTypeHandler(ICDSPluginExecutionContext executionContext) { var req = executionContext.CreateOrganizationRequest <ccllc_BTF_GetAvailableTransactionTypesRequest>(); if (string.IsNullOrEmpty(req.ContextRecordType)) { throw new ArgumentNullException("ContextRecordType cannot be null."); } if (string.IsNullOrEmpty(req.ContextRecordId)) { throw new ArgumentNullException("ContextRecordId cannot be null."); } if (!Guid.TryParse(req.ContextRecordId, out Guid recordId)) { throw new ArgumentException("ContextRecordId cannot be converted to a GUID."); } var contextRecordId = new RecordPointer <Guid>(req.ContextRecordType, recordId); var userId = req.UserId ?? new EntityReference("systemuser", executionContext.InitiatingUserId); var systemUser = new SystemUser(userId.LogicalName, userId.Id, userId.Name); var platformManager = Container.Resolve <IPlatformService>(); var session = platformManager.GenerateSession(executionContext, systemUser); var contextFactory = Container.Resolve <ITransactionContextFactory>(); var transactionContext = contextFactory.CreateTransactionContext(executionContext, contextRecordId); var serviceFactory = Container.Resolve <ITransactionServiceFactory>(); var service = serviceFactory.CreateTransactionService(executionContext); var available = service.GetAvaialbleTransactionTypes(executionContext, session, transactionContext); executionContext.OutputParameters["TransactionTypes"] = available.Serialize(); }
internal void InitiateTransactionHandler(ICDSPluginExecutionContext executionContext) { var req = (executionContext.CreateOrganizationRequest <ccllc_BTF_InitiateTransactionRequest>()); if (string.IsNullOrEmpty(req.ContextRecordType)) { throw new ArgumentNullException("ContextRecordType cannot be null."); } if (string.IsNullOrEmpty(req.ContextRecordId)) { throw new ArgumentNullException("ContextRecordId cannot be null."); } if (!Guid.TryParse(req.ContextRecordId, out Guid recordId)) { throw new ArgumentException("ContextRecordId cannot be converted to a GUID."); } var contextRecordId = new RecordPointer <Guid>(req.ContextRecordType, recordId); var transactionTypeId = req.TransactionTypeId ?? throw new NullReferenceException("TransactionTypeId cannot be null"); var userId = req.UserId ?? new EntityReference("systemuser", executionContext.InitiatingUserId); var systemUser = new SystemUser(userId.LogicalName, userId.Id, userId.Name); var platformService = Container.Resolve <IPlatformService>(); var session = platformService.GenerateSession(executionContext, systemUser); var contextFactory = Container.Resolve <ITransactionContextFactory>(); var transactionContext = contextFactory.CreateTransactionContext(executionContext, contextRecordId); var serviceFactory = Container.Resolve <ITransactionServiceFactory>(); var service = serviceFactory.CreateTransactionService(executionContext); var transactionType = service.GetAvaialbleTransactionTypes(executionContext, session, transactionContext).Where(r => r.Id == transactionTypeId.Id).FirstOrDefault(); if (transactionType == null) { throw TransactionException.BuildException(TransactionException.ErrorCode.TransactionTypeNotFound); } var transaction = service.NewTransaction(executionContext, session, transactionContext, transactionType); IUIPointer uiPointer = null; if (transaction.CurrentStep.Type.IsUIStep) { uiPointer = transaction.CurrentStep.GetUIPointer(executionContext, transaction); } if (uiPointer == null) { // When current step is not a UI step, navigate the process forward which will execute process steps // until a UI step is found or the process is blocked by a validation issue. var step = transaction.NavigateForward(session); if (step.Type.IsUIStep) { uiPointer = step.GetUIPointer(executionContext, transaction); } } if (uiPointer == null) { // At this point something is wrong so navigate the user to the transaction error form. uiPointer = new UIPointer { UIDefinition = "TransactionError", UIRecordId = transaction.Id, UIRecordType = "ccllc_transaction", UIType = eUIStepTypeEnum.DataForm }; } executionContext.Trace("Adding UI Pointer to output parameters."); executionContext.OutputParameters["UIPointer"] = uiPointer.Serialize(); }