// crm service /// <summary> /// Retrieve Entity from Crm service proxy /// </summary> /// <param name="cservice">Crm Service proxy</param> /// <param name="entityName">Entity Name</param> /// <param name="entityGuid">Entity Guid (Guid)</param> /// <returns></returns> public static DynamicEntity RetriveDynamicEntity(this CrmService cservice, String entityName, Guid entityGuid, Boolean retrieveAllColumns) { // Create/Set the Target object. TargetRetrieveDynamic targetRetrieve = new TargetRetrieveDynamic { EntityName = entityName, EntityId = (entityGuid) }; // Create/Set the Retrieve object. RetrieveRequest retrieve = new RetrieveRequest(); retrieve.Target = targetRetrieve; if (retrieveAllColumns == true) { retrieve.ColumnSet = new AllColumns(); } //// Indicate to retrieve all columns retrieve.ReturnDynamicEntities = true; // Indicate that the BusinessEntity should be retrieved as a DynamicEntity. // Execute the request. RetrieveResponse retrieved = (RetrieveResponse)cservice.Execute(retrieve); // Extract the DynamicEntity from the request. DynamicEntity retriveEntity = (DynamicEntity)retrieved.BusinessEntity; return(retriveEntity); }
/// <summary> /// Get entity /// </summary> /// <param name="organizationService">Organization Service</param> /// <param name="entityReference">Entity Reference</param> /// <param name="attributes">Attributes to return</param> /// <remarks> /// Get entity record /// </remarks> protected static Entity RetrieveEntity(Microsoft.Xrm.Sdk.EntityReference entityReference, string[] attributes, IOrganizationService organizationService) { Entity entity = null; ColumnSet columnSet = new ColumnSet(true); if (attributes != null && attributes.Length > 0) { columnSet = new ColumnSet(attributes); } try { if (entityReference != null && !entityReference.Id.Equals(Guid.Empty)) { RetrieveResponse retrieveResponse = (RetrieveResponse)organizationService.Execute(new RetrieveRequest() { ColumnSet = columnSet, Target = entityReference }); if (retrieveResponse != null && retrieveResponse.Entity != null) { entity = retrieveResponse.Entity; } } } catch { entity = null; } return(entity); }
private static object CloneResponse(RetrieveResponse response) { var clone = new RetrieveResponse(); clone["Entity"] = response.Entity.Clone(); return(clone); }
private OrganizationResponse CallOrganizationServiceRequestForExecuteRequest(OrganizationRequest request) { OrganizationResponse response = null; var associate = request as AssociateRequest; if (associate != null) { response = new AssociateResponse(); Associate(associate.Target.LogicalName, associate.Target.Id, associate.Relationship, associate.RelatedEntities); } var create = request as CreateRequest; if (create != null) { response = new CreateResponse(); response["id"] = Create(create.Target); } var delete = request as DeleteRequest; if (delete != null) { response = new DeleteResponse(); Delete(delete.Target.LogicalName, delete.Target.Id); } var disassociate = request as DisassociateRequest; if (disassociate != null) { response = new AssociateResponse(); Disassociate(disassociate.Target.LogicalName, disassociate.Target.Id, disassociate.Relationship, disassociate.RelatedEntities); } var retrieve = request as RetrieveRequest; if (retrieve != null) { response = new RetrieveResponse(); response["Entity"] = Retrieve(retrieve.Target.LogicalName, retrieve.Target.Id, retrieve.ColumnSet); } var retrieveMultiple = request as RetrieveMultipleRequest; if (retrieveMultiple != null) { response = new RetrieveMultipleResponse(); response["EntityCollection"] = RetrieveMultiple(retrieveMultiple.Query); } var update = request as UpdateRequest; if (update != null) { response = new UpdateResponse(); Update(update.Target); } return(response); }
public RetrieveResponse <WorkHours> RetrieveWorkHours(IDbConnection connection, RetrieveRequest request) { var entity = new MyRepository().Retrieve(connection, request); var workDaysFlds = CabinetWorkDaysRow.Fields; var cabinetWorkDays = connection.List <CabinetWorkDaysRow>(workDaysFlds.CabinetId == entity.Entity.CabinetId.Value).Select(x => x.WeekDayId); var model = new WorkHours { start = TimeSpan.FromMinutes(entity.Entity.WorkHoursStart ?? 420).ToString(@"hh\:mm"), end = TimeSpan.FromMinutes(entity.Entity.WorkHoursEnd ?? 1200).ToString(@"hh\:mm"), }; model.workDays = new List <Int32> { 1, 2, 3, 4, 5 }.ToJson(); if (cabinetWorkDays.Any()) { model.workDays = cabinetWorkDays.OrderBy(s => s).ToJson(); } var response = new RetrieveResponse <WorkHours>(); response.Entity = model; return(response); }
/// <summary> /// Return a single record as a dynamic entity based on a given Guid /// </summary> /// <param name="entityName"></param> /// <param name="entityId"></param> /// <param name="attributes"></param> /// <returns></returns> internal Entity RetrieveByIdAsDynamicEntity(string entityName, Guid entityId, params string[] attributes) { Entity retrieveTarget = new Entity("entityName"); retrieveTarget.Id = entityId; RetrieveRequest retrieveRequest = new RetrieveRequest(); retrieveRequest.Target = new EntityReference(entityName, entityId); ColumnSet cols = new ColumnSet(); cols.Columns.AddRange(attributes); retrieveRequest.ColumnSet = cols; RetrieveResponse resp = (RetrieveResponse)svcAct.Command_Execute(retrieveRequest, "RetrieveByIdAsDynamicEntity"); if (resp != null && resp.Entity != null) { return(resp.Entity); } else { return(null); } }
// crm service /// <summary> /// Retrieve Entity from Crm service proxy /// </summary> /// <param name="cservice">Crm Service proxy</param> /// <param name="entityName">Entity Name</param> /// <param name="entityGuid">Entity Guid (String)</param> /// <returns></returns> public static DynamicEntity RetriveDynamicEntity(this CrmService cservice, String entityName, String entityGuid) { // Create/Set the Target object. TargetRetrieveDynamic targetRetrieve = new TargetRetrieveDynamic { EntityName = entityName, EntityId = new Guid(entityGuid) }; // Create/Set the Retrieve object. RetrieveRequest retrieve = new RetrieveRequest { Target = targetRetrieve, //ColumnSet = new AllColumns(), ReturnDynamicEntities = true // Indicate that the BusinessEntity should be retrieved as a DynamicEntity. }; // Execute the request. RetrieveResponse retrieved = (RetrieveResponse)cservice.Execute(retrieve); // Extract the DynamicEntity from the request. DynamicEntity retriveEntity = (DynamicEntity)retrieved.BusinessEntity; return(retriveEntity); }
public object Execute(object request) { if (request.GetType().Name == "RetrieveMultipleRequest") { RetrieveMultipleResponse response = new RetrieveMultipleResponse(); response.BusinessEntityCollection = RetrieveMultiple((( RetrieveMultipleRequest )request).Query); return(response); } else if (request.GetType().Name == "RetrieveRequest") { RetrieveResponse response = new RetrieveResponse(); RetrieveRequest retrieveRequest = ( RetrieveRequest )request; TargetRetrieve target = retrieveRequest.Target; if (target.GetType().Name == "TargetRetrieveDynamic") { TargetRetrieveDynamic trd = ( TargetRetrieveDynamic )target; response.BusinessEntity = Retrieve(trd.EntityName, trd.EntityId, retrieveRequest.ColumnSet); } else { // request sent using a specific strongly-typed business entity // rather than a DynamicEntity throw new NotImplementedException(); } return(response); } else { throw new NotImplementedException(); } }
private static object CloneResponse(RetrieveResponse response) { var clone = new RetrieveResponse { ResponseName = response.ResponseName }; clone["Entity"] = Microsoft.Xrm.Client.EntityExtensions.Clone(response.Entity); return(clone); }
private RetrieveResponse HandleRetrieve(OrganizationRequest orgRequest, EntityReference userRef) { var request = MakeRequest <RetrieveRequest>(orgRequest); var resp = new RetrieveResponse(); var settings = MockupExecutionContext.GetSettings(request); resp.Results["Entity"] = dataMethods.Retrieve(request.Target, request.ColumnSet, request.RelatedEntitiesQuery, settings.SetUnsettableFields, userRef); return(resp); }
/// <summary>The get dependencies.</summary> /// <param name="response">The response.</param> /// <param name="path">The path.</param> /// <returns>The dependencies.</returns> private IEnumerable <string> GetDependencies(RetrieveResponse response, IEnumerable <object> path) { yield return(this.GetTag(TagSingle)); foreach (var dependency in this.GetDependenciesForObject(response.Entity, true, path)) { yield return(dependency); } }
protected void PullThePlugin(LocalPluginContext localContext) { if (!localContext.PluginExecutionContext.InputParameters.Contains("RecordId")) { return; } string RecordId = (string)localContext.PluginExecutionContext.InputParameters["RecordId"]; IOrganizationService service = localContext.OrganizationService; Relationship relationship = new Relationship(); relationship.SchemaName = "new_new_task12child_new_task12main"; QueryExpression query = new QueryExpression(); query.EntityName = "new_task12child"; query.ColumnSet = new ColumnSet(true); query.Criteria = new FilterExpression(); query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, "Active")); RelationshipQueryCollection relatedEntity = new RelationshipQueryCollection(); relatedEntity.Add(relationship, query); RetrieveRequest request = new RetrieveRequest(); request.ColumnSet = new ColumnSet("new_name"); request.Target = new EntityReference { Id = new Guid(RecordId), LogicalName = "new_task12main" }; request.RelatedEntitiesQuery = relatedEntity; RetrieveResponse response = (RetrieveResponse)service.Execute(request); DataCollection <Entity> RelatedEntitis = ((DataCollection <Relationship, EntityCollection>) (((RelatedEntityCollection)(response.Entity.RelatedEntities)))) [new Relationship("new_new_task12child_new_task12main")].Entities; foreach (var RelatedEntity in RelatedEntitis) { SetStateRequest setStateRequest = new SetStateRequest() { EntityMoniker = new EntityReference { Id = RelatedEntity.Id, LogicalName = RelatedEntity.LogicalName, }, State = new OptionSetValue(1), Status = new OptionSetValue(2) }; service.Execute(setStateRequest); } localContext.PluginExecutionContext.OutputParameters["Out"] = string.Format("Deativated {0} ", RelatedEntitis.Count); }
internal override OrganizationResponse Execute(OrganizationRequest orgRequest, EntityReference userRef) { var request = MakeRequest <RetrieveRequest>(orgRequest); var settings = MockupExecutionContext.GetSettings(request); if (request.Target.LogicalName == null) { throw new FaultException("You must provide a LogicalName"); } #if !(XRM_MOCKUP_2011 || XRM_MOCKUP_2013 || XRM_MOCKUP_2015) if (request.ColumnSet == null && request.Target.KeyAttributes.Count == 0) { throw new FaultException("The columnset parameter must not be null when no KeyAttributes are provided"); } #else if (request.ColumnSet == null) { throw new FaultException("The columnset parameter must not be null"); } #endif var row = db.GetDbRow(request.Target); if (!security.HasPermission(row.ToEntity(), AccessRights.ReadAccess, userRef)) { throw new FaultException($"Calling user with id '{userRef.Id}' does not have permission to read entity '{row.Table.TableName}'"); } #if !(XRM_MOCKUP_2011 || XRM_MOCKUP_2013) core.ExecuteCalculatedFields(row); #endif row = db.GetDbRow(request.Target); var entity = core.GetStronglyTypedEntity(row.ToEntity(), row.Metadata, request.ColumnSet); Utility.SetFormmattedValues(db, entity, row.Metadata); if (!settings.SetUnsettableFields) { Utility.RemoveUnsettableAttributes("Retrieve", row.Metadata, entity); } #if !(XRM_MOCKUP_2011 || XRM_MOCKUP_2013) Utility.HandlePrecision(metadata, db, entity); #endif if (request.RelatedEntitiesQuery != null) { core.AddRelatedEntities(entity, request.RelatedEntitiesQuery, userRef); } var resp = new RetrieveResponse(); resp.Results["Entity"] = entity; return(resp); }
public OrganizationResponse Execute(OrganizationRequest request) { if (request.GetType().Name == "RetrieveMultipleRequest") { RetrieveMultipleResponse response = new RetrieveMultipleResponse(); EntityCollection result = RetrieveMultiple((( RetrieveMultipleRequest )request).Query); response.Results["EntityCollection"] = result; return(response); } else if (request.GetType().Name == "RetrieveRequest") { RetrieveResponse response = new RetrieveResponse(); RetrieveRequest retrieveRequest = ( RetrieveRequest )request; EntityReference target = retrieveRequest.Target; if (target.GetType().Name == "TargetRetrieveDynamic") { /* * TargetRetrieveDynamic trd = ( TargetRetrieveDynamic )target; * response.Entity = Retrieve( trd.EntityName, trd.EntityId, retrieveRequest.ColumnSet ); */ } // TODO: entity is readonly .. will have to set this with reflection // response.Entity = Retrieve( target.LogicalName, target.Id, retrieveRequest.ColumnSet ); else { // request sent using a specific strongly-typed business entity // rather than a DynamicEntity throw new NotImplementedException(); } return(response); } else if (request.GetType().Name == "CreateRequest") { CreateResponse response = new CreateResponse(); Guid result = Create((( CreateRequest )request).Target); response.Results["id"] = result; return(response); } else if (request.GetType().Name == "UpdateRequest") { UpdateResponse response = new UpdateResponse(); Update((( UpdateRequest )request).Target); return(response); } else { throw new NotImplementedException(); } }
public T GetRecord <T>(string keyName, object keyValue, string[] columnNames) where T : Entity { RetrieveRequest request = new RetrieveRequest { ColumnSet = new ColumnSet(columnNames), Target = new EntityReference(GetEntityLogicalName <T>(), keyName, keyValue) }; RetrieveResponse response = (RetrieveResponse)ServiceProxy.Execute(request); return(response.Entity.ToEntity <T>()); }
public ActionResult Details(int id) { Administration.Repositories.UserRepository repo = new Administration.Repositories.UserRepository(); RetrieveRequest request = new RetrieveRequest(); RetrieveResponse <Administration.Entities.UserRow> response = new RetrieveResponse <Administration.Entities.UserRow>(); using (var connection = SqlConnections.NewByKey("Rukuntangga")) { request.EntityId = id; response = repo.Retrieve(connection, request); } return(PartialView(MVC.Views.Rukuntangga.UserMember.UserMemberIndex, response.Entity)); }
public ActionResult Details(int id) { TbKtpRepository repo = new TbKtpRepository(); RetrieveRequest request = new RetrieveRequest(); RetrieveResponse <TbKtpRow> response = new RetrieveResponse <TbKtpRow>(); using (var connection = SqlConnections.NewByKey("Rukuntangga")) { request.EntityId = id; response = repo.Retrieve(connection, request); } return(PartialView(MVC.Views.Rukuntangga.Warga.WargaDetail, response.Entity)); }
/// <summary> /// Retrieve method override. Retrieves by Alternative key /// </summary> /// <param name="keyName">Name of alternative key</param> /// <param name="keyValue">Key value</param> public static Entity Retrieve(this IOrganizationService service, string logicalName, KeyAttributeCollection keyAttributeCollection, ColumnSet columnSet) { CheckParam.CheckForNull(logicalName, nameof(logicalName)); CheckParam.CheckForNull(keyAttributeCollection, nameof(keyAttributeCollection)); RetrieveResponse response = service.Execute(new RetrieveRequest() { Target = new EntityReference(logicalName, keyAttributeCollection), ColumnSet = columnSet }) as RetrieveResponse; return(response.Entity); }
public ActionResult Detail(int id = 0) { RetrieveRequest request = new RetrieveRequest(); RetrieveResponse <TbDetailJenisKegiatanRow> response = new RetrieveResponse <TbDetailJenisKegiatanRow>(); TbDetailJenisKegiatanRepository repository = new TbDetailJenisKegiatanRepository(); using (var connection = SqlConnections.NewByKey("Rukuntangga")) { request.EntityId = id; response = repository.Retrieve(connection, request); } return(View(MVC.Views.Rukuntangga.Aktifitas._AktifitasDetail, response.Entity)); }
public ActionResult DetailPemilu(int id) { RetrieveRequest request = new RetrieveRequest(); RetrieveResponse <TbDetailPemiluRow> response = new RetrieveResponse <TbDetailPemiluRow>(); TbDetailPemiluRepository repository = new TbDetailPemiluRepository(); using (var connection = SqlConnections.NewByKey("Rukuntangga")) { request.EntityId = id; response = repository.Retrieve(connection, request); } return(PartialView(MVC.Views.Rukuntangga.Questioner._QuestionerDetailPemilu, response.Entity)); }
public RetrieveResponse <TRow> Retrieve(IDbConnection connection, RetrieveLocalizationRequest request) { request.CheckNotNull(); if (request.EntityId == null) { throw new ArgumentNullException("entityId"); } if (request.CultureId == null) { throw new ArgumentNullException("cultureId"); } var row = new TRow(); row.TrackAssignments = true; row.IdField[row] = request.EntityId.Value; var recordId = request.EntityId.Value; var idField = ((IIdRow)row).IdField; var localRow = GetOldLocalizationRow(connection, recordId, request.CultureId.Value); var response = new RetrieveResponse <TRow>(); response.Entity = row; if (localRow == null) { return(response); } foreach (var field in row.GetFields()) { if (ReferenceEquals(field, idField)) { continue; } var match = GetLocalizationMatch(field); if (!ReferenceEquals(null, match)) { var value = match.AsObject(localRow); field.AsObject(row, value); } } return(response); }
private OrganizationResponse CallOrganizationServiceRequestForExecuteRequest(OrganizationRequest request) { OrganizationResponse response = null; if (request is AssociateRequest associate) { response = new AssociateResponse(); Associate(associate.Target.LogicalName, associate.Target.Id, associate.Relationship, associate.RelatedEntities); } if (request is CreateRequest create) { response = new CreateResponse { ["id"] = Create(create.Target) }; } if (request is DeleteRequest delete) { response = new DeleteResponse(); Delete(delete.Target.LogicalName, delete.Target.Id); } if (request is DisassociateRequest disassociate) { response = new AssociateResponse(); Disassociate(disassociate.Target.LogicalName, disassociate.Target.Id, disassociate.Relationship, disassociate.RelatedEntities); } if (request is RetrieveRequest retrieve) { response = new RetrieveResponse { ["Entity"] = Retrieve(retrieve.Target.LogicalName, retrieve.Target.Id, retrieve.ColumnSet) }; } if (request is RetrieveMultipleRequest retrieveMultiple) { response = new RetrieveMultipleResponse { ["EntityCollection"] = RetrieveMultiple(retrieveMultiple.Query) }; } if (request is UpdateRequest update) { response = new UpdateResponse(); Update(update.Target); } return(response); }
public static void Calculate(CodeActivityContext Workflowcontext, Lead newLead) { EntityReference LeadEnt = Lead.Get(Workflowcontext); if (LeadEnt == null) { throw new InvalidOperationException("LeadEntity has not been specified", new ArgumentNullException("LeadEntity")); } else if (LeadEnt.LogicalName != LeadEntity) { throw new InvalidOperationException("LeadEntity must reference a LeadEntity ", new ArgumentException("LeadEntity must be of type Lead", "LeadEntity")); } ITracingService tracingService = Workflowcontext.GetExtension <ITracingService>(); IWorkflowContext context = Workflowcontext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = Workflowcontext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId); Lead new_lead; { RetrieveRequest request = new RetrieveRequest(); request.ColumnSet = new ColumnSet(new string[] { "apuk_marketingpermission", "donotphone", "apuk_donotsms", "donotemail", "donotpostalmail" }); request.Target = LeadEnt; RetrieveResponse retrieveResponse = (RetrieveResponse)service.Execute(request); new_lead = retrieveResponse.Entity as Lead; } if (context.Depth == 1) { if ((int)new_lead.apuk_MarketingPermission.Value == (int)MarketingPermissionaccess.DoNotAllow) { new_lead.apuk_donotsms = false; new_lead.DoNotPhone = true; new_lead.DoNotEMail = true; new_lead.DoNotPostalMail = true; } if (new_lead.apuk_donotsms == false && new_lead.DoNotPhone == true && new_lead.DoNotEMail == true && new_lead.DoNotPostalMail == true) { new_lead.apuk_MarketingPermission = new OptionSetValue((int)MarketingPermissionaccess.DoNotAllow); } service.Update(new_lead); } }
static void Main(string[] args) { OrganizationServiceProxy serviceProxy = ConnectHelper.CrmService; var service = (IOrganizationService)serviceProxy; Relationship relationship = new Relationship(); relationship.SchemaName = "new_new_task12child_new_task12main"; QueryExpression query = new QueryExpression(); query.EntityName = "new_task12child"; query.ColumnSet = new ColumnSet(true); query.Criteria = new FilterExpression(); query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, "Active")); RelationshipQueryCollection relatedEntity = new RelationshipQueryCollection(); relatedEntity.Add(relationship, query); RetrieveRequest request = new RetrieveRequest(); request.ColumnSet = new ColumnSet("new_name"); request.Target = new EntityReference { Id = new Guid("{DE4B6AB0-7F9A-E911-8122-00155D06F203}"), LogicalName = "new_task12main" }; request.RelatedEntitiesQuery = relatedEntity; RetrieveResponse response = (RetrieveResponse)service.Execute(request); Console.WriteLine("NameMain: " + response.Entity["new_name"]); DataCollection <Entity> RelatedEntitis = ((DataCollection <Relationship, EntityCollection>) (((RelatedEntityCollection)(response.Entity.RelatedEntities)))) [new Relationship("new_new_task12child_new_task12main")].Entities; Console.WriteLine("Related Childs:"); foreach (var RelatedEntity in RelatedEntitis) { Console.WriteLine(" - " + RelatedEntity["new_name"] + "Id: " + RelatedEntity.Id); } Console.WriteLine("Press Enter"); Console.ReadLine(); }
protected override void Execute(CodeActivityContext context) { ITracingService tracingService = context.GetExtension <ITracingService>(); IWorkflowContext WorkflowContext = context.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = context.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(WorkflowContext.UserId); EntityReference _CreatedByValue = CreatedByValue.Get(context); EntityReference _ModifiedByValue = ModifiedByValue.Get(context); DateTime _ModifiedOnValue = ModifiedOnValue.Get(context); Entity entity = (Entity)WorkflowContext.InputParameters["Target"]; #region CreatedBy if (_CreatedByValue != null) { tracingService.Trace("Entering CreateBy Zone"); Entity CreatedByEntity; { //Create a request RetrieveRequest retrieveRequest = new RetrieveRequest(); retrieveRequest.ColumnSet = new ColumnSet(new string[] { "systemuserid", "fullname" }); retrieveRequest.Target = _CreatedByValue; //Execute the request RetrieveResponse retrieveResponse = (RetrieveResponse)service.Execute(retrieveRequest); //Retrieve the Loan Application Entity CreatedByEntity = retrieveResponse.Entity as Entity; tracingService.Trace("NewCreatedBy = " + Convert.ToString(CreatedByEntity.Attributes["fullname"])); } } Entity updateEntity = new Entity(entity.LogicalName); updateEntity["createdby"] = _CreatedByValue; //hasta este punto no estaba funcionando ya que la intervención debe realizarse antes de la creación y el custom workflow activity no permite hacerlo de ese modo. service.Update(updateEntity); #endregion #region ModifiedBy #endregion #region ModifiedOn #endregion }
public ActionResult Index() { TbKtpRepository repo = new TbKtpRepository(); RetrieveRequest request = new RetrieveRequest(); RetrieveResponse <TbKtpRow> response = new RetrieveResponse <TbKtpRow>(); using (var connection = SqlConnections.NewByKey("Rukuntangga")) { var ud = (UserDefinition)Serenity.Authorization.UserDefinition; request.EntityId = ud.Ktp.Id; response = repo.Retrieve(connection, request); } return(View(MVC.Views.Rukuntangga.Profile.ProfileIndex, response.Entity)); }
/// <summary> /// Method retrieves target components /// </summary> /// <param name="serviceProxy">service proxy</param> /// <param name="retrieveResponse">retrieve response</param> /// <param name="queryExpressionType">query expression type</param> private void QueryTargetComponents(IOrganizationService serviceProxy, RetrieveResponse retrieveResponse, string queryExpressionType) { var qe = new QueryExpression(queryExpressionType) { ColumnSet = new ColumnSet(true), Criteria = new FilterExpression { Conditions = { new ConditionExpression("name", ConditionOperator.Equal, retrieveResponse.Entity.Attributes["name"].ToString()), } } }; EntityCollection solutionComponents = serviceProxy.RetrieveMultiple(qe); Entity solutionCom = solutionComponents.Entities[0]; }
private ExecuteMultipleResponseItem GetRetrieveResponseItem(int requestIndex, Entity updatedContactEntity) { var retrieveResponse = new RetrieveResponse { Results = new ParameterCollection { { "Entity", updatedContactEntity } } }; var retrieveResponseItem = new ExecuteMultipleResponseItem(); retrieveResponseItem.RequestIndex = requestIndex; retrieveResponseItem.Response = retrieveResponse; return(retrieveResponseItem); }
public RetrieveResponse <string> RetrieveEmailSignature(IDbConnection connection, RetrieveRequest request) { var user = (UserDefinition)Authorization.UserDefinition; var response = new RetrieveResponse <string>(); //Get Email Signature if (connection.ById <TenantRow>(user.TenantId).OverrideUsersEmailSignature ?? false) { response.Entity = connection.ById <TenantRow>(user.TenantId).TenantEmailSignature; } else { response.Entity = connection.ById <UserRow>(user.UserId).EmailSignature; } return(response); }
/// <summary> /// GetAssociatedEntityItems method is to get related entity details /// </summary> /// <param name="primaryEntityName"></param> /// <param name="_primaryEntityId"></param> /// <param name="relatedEntityName"></param> /// <param name="relationshipName"></param> /// <param name="serviceProxy"></param> /// <returns></returns> private EntityCollection GetAssociatedEntityItems(string primaryEntityName, Guid _primaryEntityId, string relatedEntityName, string relationshipName, IOrganizationService serviceProxy) { try { tracingService.Trace("Entering into InvokeWorkflows method...."); EntityCollection result = null; QueryExpression relatedEntityQuery = new QueryExpression(); relatedEntityQuery.EntityName = relatedEntityName; relatedEntityQuery.ColumnSet = new ColumnSet(false); Relationship relationship = new Relationship(); relationship.SchemaName = relationshipName; //relationship.PrimaryEntityRole = EntityRole.Referencing; RelationshipQueryCollection relatedEntity = new RelationshipQueryCollection(); relatedEntity.Add(relationship, relatedEntityQuery); RetrieveRequest request = new RetrieveRequest(); request.RelatedEntitiesQuery = relatedEntity; request.ColumnSet = new ColumnSet(true); request.Target = new EntityReference { Id = _primaryEntityId, LogicalName = primaryEntityName }; RetrieveResponse response = (RetrieveResponse)serviceProxy.Execute(request); RelatedEntityCollection relatedEntityCollection = response.Entity.RelatedEntities; tracingService.Trace("After get the RelatedEntityCollection"); if (relatedEntityCollection != null) { tracingService.Trace("RelatedEntityCollection Count: {0}, RelatedEntityCollection.Values.Count:{1}", relatedEntityCollection.Count, relatedEntityCollection.Values.Count); if (relatedEntityCollection.Count > 0 && relatedEntityCollection.Values.Count > 0) { result = (EntityCollection)relatedEntityCollection.Values.ElementAt(0); } } return(result); } catch (Exception ex) { throw; } }
private OrganizationResponse CallOrganizationServiceRequestForExecuteRequest(OrganizationRequest request) { OrganizationResponse response = null; var associate = request as AssociateRequest; if (associate != null) { response = new AssociateResponse(); Associate(associate.Target.LogicalName, associate.Target.Id, associate.Relationship, associate.RelatedEntities); } var create = request as CreateRequest; if (create != null) { response = new CreateResponse(); response["id"] = Create(create.Target); } var delete = request as DeleteRequest; if (delete != null) { response = new DeleteResponse(); Delete(delete.Target.LogicalName, delete.Target.Id); } var disassociate = request as DisassociateRequest; if (disassociate != null) { response = new AssociateResponse(); Disassociate(disassociate.Target.LogicalName, disassociate.Target.Id, disassociate.Relationship, disassociate.RelatedEntities); } var retrieve = request as RetrieveRequest; if (retrieve != null) { response = new RetrieveResponse(); response["Entity"] = Retrieve(retrieve.Target.LogicalName, retrieve.Target.Id, retrieve.ColumnSet); } var retrieveMultiple = request as RetrieveMultipleRequest; if (retrieveMultiple != null) { response = new RetrieveMultipleResponse(); response["EntityCollection"] = RetrieveMultiple(retrieveMultiple.Query); } var update = request as UpdateRequest; if (update != null) { response = new UpdateResponse(); Update(update.Target); } return response; }
public object Execute( object request ) { if( request.GetType().Name == "RetrieveMultipleRequest" ) { RetrieveMultipleResponse response = new RetrieveMultipleResponse(); response.BusinessEntityCollection = RetrieveMultiple( ( ( RetrieveMultipleRequest )request ).Query ); return response; } else if(request.GetType().Name == "RetrieveRequest" ) { RetrieveResponse response = new RetrieveResponse(); RetrieveRequest retrieveRequest = ( RetrieveRequest )request; TargetRetrieve target = retrieveRequest.Target; if( target.GetType().Name == "TargetRetrieveDynamic" ) { TargetRetrieveDynamic trd = ( TargetRetrieveDynamic )target; response.BusinessEntity = Retrieve( trd.EntityName, trd.EntityId, retrieveRequest.ColumnSet ); } else { // request sent using a specific strongly-typed business entity // rather than a DynamicEntity throw new NotImplementedException(); } return response; } else { throw new NotImplementedException(); } }
public OrganizationResponse Execute( OrganizationRequest request ) { if( request.GetType().Name == "RetrieveMultipleRequest" ) { RetrieveMultipleResponse response = new RetrieveMultipleResponse(); EntityCollection result = RetrieveMultiple( ( ( RetrieveMultipleRequest )request ).Query ); response.Results[ "EntityCollection" ] = result; return response; } else if(request.GetType().Name == "RetrieveRequest" ) { RetrieveResponse response = new RetrieveResponse(); RetrieveRequest retrieveRequest = ( RetrieveRequest )request; EntityReference target = retrieveRequest.Target; if( target.GetType().Name == "TargetRetrieveDynamic" ) { /* TargetRetrieveDynamic trd = ( TargetRetrieveDynamic )target; response.Entity = Retrieve( trd.EntityName, trd.EntityId, retrieveRequest.ColumnSet ); */ } // TODO: entity is readonly .. will have to set this with reflection // response.Entity = Retrieve( target.LogicalName, target.Id, retrieveRequest.ColumnSet ); else { // request sent using a specific strongly-typed business entity // rather than a DynamicEntity throw new NotImplementedException(); } return response; } else if( request.GetType().Name == "CreateRequest" ) { CreateResponse response = new CreateResponse(); Guid result = Create( ( ( CreateRequest )request ).Target ); response.Results[ "id" ] = result; return response; } else if( request.GetType().Name == "UpdateRequest" ) { UpdateResponse response = new UpdateResponse(); Update( ( ( UpdateRequest )request).Target ); return response; } else { throw new NotImplementedException(); } }