protected override void Execute(CodeActivityContext executionContext) { ITracingService tracingService = executionContext.GetExtension <ITracingService>(); IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); tracingService.Trace("{0}{1}", "Start Custom Workflow Activity: GetNextProjectRequestNumber", DateTime.Now.ToLongTimeString()); //Get Project field var projectToCreate = new caps_Project(); var projectId = service.Create(projectToCreate); //get project Id Microsoft.Xrm.Sdk.Query.ColumnSet columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("caps_projectcode"); var projectRecord = service.Retrieve(caps_Project.EntityLogicalName, projectId, columns) as caps_Project; var projectNumber = projectRecord.caps_ProjectCode; tracingService.Trace("Project Number:{0}", projectNumber); projectRequestNumber.Set(executionContext, projectNumber); //delete project service.Delete(caps_Project.EntityLogicalName, projectId); }
internal QueryResultContainer(Microsoft.Xrm.Sdk.Query.ColumnSet columns, EntityShadow[] initialEntities, string logicalName) { this.columns.Add("", new AliasContainer { Alias = string.Empty, LogicalName = logicalName, ColumnSet = columns }); this.logicalName = logicalName; this.Entities = initialEntities.Select(r => new EntityContainer(r)).ToArray(); }
internal static string[] ToAttributNames(this Microsoft.Xrm.Sdk.Query.ColumnSet columnSet) { if (columnSet == null) { return(new string[0]); } if (columnSet.AllColumns) { return(null); } if (columnSet.Columns == null) { return(new string[0]); } return(columnSet.Columns.ToArray()); }
protected override void Execute(CodeActivityContext executionContext) { ITracingService tracingService = executionContext.GetExtension <ITracingService>(); IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); tracingService.Trace("{0}{1}", "Start Custom Workflow Activity: CheckCOACreationRules", DateTime.Now.ToLongTimeString()); //Get Project field Microsoft.Xrm.Sdk.Query.ColumnSet columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("caps_ptr"); var coaRecord = service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, columns) as caps_CertificateofApproval; //might want to return an error if this is missing a Project if (coaRecord.caps_PTR == null || coaRecord.caps_PTR.Id == null) { return; } //Set default values for outputs var error = false; var errorMessage = ""; using (var crmContext = new CrmServiceContext(service)) { //Check if there are any other COAs for this project in a Draft or Submitted State var records = crmContext.caps_CertificateofApprovalSet.Where(r => r.caps_PTR.Id == coaRecord.caps_PTR.Id && r.caps_CertificateofApprovalId != context.PrimaryEntityId && (r.StatusCode.Value == (int)caps_CertificateofApproval_StatusCode.Draft || r.StatusCode.Value == (int)caps_CertificateofApproval_StatusCode.Submitted)).ToList(); if (records.Count() > 0) { //Start Year was already used so need to display error. error = true; errorMessage = "Unable to create COA as there is already a Draft or Submitted one for this Project."; } this.error.Set(executionContext, error); this.errorMessage.Set(executionContext, errorMessage); } }
public Entity Retrieve(string entityName, Guid id, Microsoft.Xrm.Sdk.Query.ColumnSet columnSet) { return(RunSafe(() => _serviceProxy.Retrieve(entityName, id, columnSet))); }
/// <summary> /// Method to get users in given Role. in CRM Marketing list. /// This method has been customized to support dynamic lists. /// </summary> /// <param name="roleName"></param> /// <returns></returns> public override string[] GetUsersInRole(string roleName) { //setting that disabled the dynamic list functionality. if (SitecoreUtility.GetSitecoreSetting <bool>("AlphaSolutions.ExtendedCRMProvider.Disable.DynamicLists", false)) { return(base.GetUsersInRole(roleName)); } Assert.ArgumentNotNull(roleName, "roleName"); ConditionalLog.Info(string.Format("GetUsersInRole({0}). Started.", roleName), this, TimerAction.Start, "getUsersInRole"); string text = base.CacheService.MembersCache.Get(roleName); if (text != null) { ConditionalLog.Info(string.Format("GetUsersInRole({0}). Finished (users have been retrieved from cache).", roleName), this, TimerAction.Stop, "getUsersInRole"); return(text.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)); } // set up a query for the list to check type Microsoft.Xrm.Sdk.Query.ColumnSet columnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(new string[] { "listname", "query", "type" }); Microsoft.Xrm.Sdk.Query.QueryExpression query = new Microsoft.Xrm.Sdk.Query.QueryExpression(); query.ColumnSet = columnSet; Microsoft.Xrm.Sdk.Query.ConditionExpression listnameCondition = new Microsoft.Xrm.Sdk.Query.ConditionExpression(); listnameCondition.AttributeName = "listname"; listnameCondition.Operator = Microsoft.Xrm.Sdk.Query.ConditionOperator.Equal; listnameCondition.Values.Add(roleName); Microsoft.Xrm.Sdk.Query.FilterExpression filterList = new Microsoft.Xrm.Sdk.Query.FilterExpression(); filterList.Conditions.Add(listnameCondition); filterList.FilterOperator = Microsoft.Xrm.Sdk.Query.LogicalOperator.And; query.EntityName = "list"; query.Criteria = filterList; // Execute the query Microsoft.Xrm.Sdk.Messages.RetrieveMultipleRequest req = new Microsoft.Xrm.Sdk.Messages.RetrieveMultipleRequest(); req.Query = query; Microsoft.Xrm.Sdk.Messages.RetrieveMultipleResponse res = (Microsoft.Xrm.Sdk.Messages.RetrieveMultipleResponse) this.OrganizationService.Execute(req); if (res != null && res.EntityCollection != null && res.EntityCollection.Entities.Count > 0) { Entity myList = res.EntityCollection.Entities[0]; if (myList.Attributes.Keys.Contains("query")) { // Define the fetch attributes. // Set the number of records per page to retrieve. int fetchCount = Settings.FetchThrottlingPageSize; // Initialize the page number. int pageNumber = 1; // Initialize the number of records. int recordCount = 0; // Specify the current paging cookie. For retrieving the first page, // pagingCookie should be null. string pagingCookie = null; //Convert fetchXML to Query Expression var xml = myList["query"].ToString(); HashSet <string> hashSet = new HashSet <string>(); try { while (true) { string xmlpaging = CreateXml(xml, pagingCookie, pageNumber, fetchCount, Settings.UniqueKeyProperty); Microsoft.Xrm.Sdk.Query.FetchExpression f = new Microsoft.Xrm.Sdk.Query.FetchExpression(xmlpaging); RetrieveMultipleRequest retrieveMultipleRequest = new RetrieveMultipleRequest(); retrieveMultipleRequest.Query = f; RetrieveMultipleResponse retrieveMultipleResponse = (RetrieveMultipleResponse)this.OrganizationService.Execute(retrieveMultipleRequest); if (retrieveMultipleResponse != null && retrieveMultipleResponse.EntityCollection != null) { ConditionalLog.Info(string.Format("GetUsersInRole({0}). Retrieved {1} users from CRM.", roleName, retrieveMultipleResponse.EntityCollection.Entities.Count), this, TimerAction.Tick, "getUsersInRole"); foreach (Entity current in retrieveMultipleResponse.EntityCollection.Entities) { try { base.CacheService.UserCache.Add(this.ContactToUserConverter.Convert(current)); hashSet.Add((string)current[Settings.UniqueKeyProperty]); } catch (Exception e) { ConditionalLog.Error(string.Format("GetUsersInRole({0}). Error in converting contact to user. Number of attributes gotten: {1}", current.LogicalName, current.Attributes.Count), e, this); } } // Check for morerecords, if it returns 1. if (retrieveMultipleResponse.EntityCollection.MoreRecords) { // Increment the page number to retrieve the next page. pageNumber++; } else { // If no more records in the result nodes, exit the loop. break; } pagingCookie = retrieveMultipleResponse.EntityCollection.PagingCookie; } } var ret = hashSet.ToArray <string>(); base.CacheService.MembersCache.Add(roleName, string.Join("|", ret)); return(ret); } catch (System.Exception sourceException) { ConditionalLog.Error(string.Format("Couldn't get contacts of {0} marketing list from CRM.", roleName), sourceException, this); } } else { return(base.GetUsersInRole(roleName)); } } return(new string[0]); }
protected override void Execute(CodeActivityContext executionContext) { ITracingService tracingService = executionContext.GetExtension <ITracingService>(); IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); tracingService.Trace("{0}{1}", "Start Custom Workflow Activity: CheckPhasedProjectYear", DateTime.Now.ToLongTimeString()); //Get Project & Phased Project Group Field Microsoft.Xrm.Sdk.Query.ColumnSet columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("caps_phasedprojectgroup", "caps_startdate", "caps_projectyear"); var projectRecord = service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, columns) as caps_Project; if (projectRecord.caps_Projectyear == null) { return; } //Set default values for outputs var error = false; var errorMessage = ""; var projectStartYear = projectRecord.caps_Projectyear.Id; tracingService.Trace("{0}:{1}", projectRecord.caps_ProjectCode, projectRecord.caps_Projectyear.Name); //get projects that are part of the phased project group using (var crmContext = new CrmServiceContext(service)) { var records = crmContext.caps_ProjectSet.Where(r => r.caps_PhasedProjectGroup.Id == projectRecord.caps_PhasedProjectGroup.Id && r.caps_ProjectId != context.PrimaryEntityId); foreach (var record in records) { ////get start date //if (record.caps_StartDate.HasValue) //{ // if (record.caps_StartDate.Value.Year == proejctStartYear) // { // //Start Year was already used so need to display error. // error = true; // errorMessage = "Another project in the phased project group is for the same year."; // break; // } //} tracingService.Trace("{0}:{1}", record.caps_ProjectCode, record.caps_Projectyear.Name); //Get Year //get start date if (record.caps_Projectyear != null) { if (record.caps_Projectyear.Id == projectStartYear) { //Start Year was already used so need to display error. error = true; errorMessage = "Another project in the phased project group is for the same year."; break; } } } this.error.Set(executionContext, error); this.errorMessage.Set(executionContext, errorMessage); } }
public Entity Retrieve(string entityName, Guid id, Microsoft.Xrm.Sdk.Query.ColumnSet columnSet) { return(m_service.Retrieve(entityName, id, columnSet)); }
public FluentChainActionWithReturn <Entity> RetrieveFluent(string entityName, Guid id, Microsoft.Xrm.Sdk.Query.ColumnSet columnSet) { return(new FluentChainActionWithReturn <Entity>(() => { return service.Retrieve(entityName, id, columnSet); })); }
public Microsoft.Xrm.Sdk.Entity Retrieve(string entityName, System.Guid id, Microsoft.Xrm.Sdk.Query.ColumnSet columnSet) { return(base.Channel.Retrieve(entityName, id, columnSet)); }
public Entity Retrieve(string entityName, Guid id, Microsoft.Xrm.Sdk.Query.ColumnSet columnSet) { throw new NotImplementedException(); }
public static Microsoft.Xrm.Sdk.Entity PrayerRetrieve(this OrganizationServiceProxy service, string entityName, Guid id, Microsoft.Xrm.Sdk.Query.ColumnSet columnSet, TimeSpan timeout, int tryCount) { TimeSpan tempTimeOut = service.Timeout; service.Timeout = timeout; int tc = tryCount; do { try { if (tc == 1) { service.Timeout = tempTimeOut; } var entity = service.Retrieve(entityName, id, columnSet); service.Timeout = tempTimeOut; return(entity); } catch (Exception e) { if (e.Message == "Generic SQL error." || e is System.Data.SqlClient.SqlException || e is TimeoutException) { tc--; if (tryCount <= 0) { service.Timeout = tempTimeOut; throw e; } } else { service.Timeout = tempTimeOut; throw e; } } } while (tryCount > 0); return(null); }
public static Microsoft.Xrm.Sdk.Entity PrayerRetrieve(this OrganizationServiceProxy service, string entityName, Guid id, Microsoft.Xrm.Sdk.Query.ColumnSet columnSet) { TimeSpan timeout = TimeSpan.FromSeconds(10); return(service.PrayerRetrieve(entityName, id, columnSet, timeout, 5)); }