//</snippetAuditing2> /// <summary> /// Enable auditing on an entity. /// </summary> /// <param name="entityLogicalName">The logical name of the entity.</param> /// <param name="flag">True to enable auditing, otherwise false.</param> /// <returns>The previous value of the IsAuditEnabled attribute.</returns> //<snippetAuditing3> private bool EnableEntityAuditing(string entityLogicalName, bool flag) { // Retrieve the entity metadata. RetrieveEntityRequest entityRequest = new RetrieveEntityRequest { LogicalName = entityLogicalName, EntityFilters = EntityFilters.Attributes }; RetrieveEntityResponse entityResponse = (RetrieveEntityResponse)_service.Execute(entityRequest); // Enable auditing on the entity. By default, this also enables auditing // on all the entity's attributes. EntityMetadata entityMetadata = entityResponse.EntityMetadata; bool oldValue = entityMetadata.IsAuditEnabled.Value; entityMetadata.IsAuditEnabled = new BooleanManagedProperty(flag); UpdateEntityRequest updateEntityRequest = new UpdateEntityRequest { Entity = entityMetadata }; UpdateEntityResponse updateEntityResponse = (UpdateEntityResponse)_service.Execute(updateEntityRequest); return(oldValue); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { UpdateEntityResponse response = new UpdateEntityResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("state", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.State = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("updateDateTime", targetDepth)) { var unmarshaller = DateTimeUnmarshaller.Instance; response.UpdateDateTime = unmarshaller.Unmarshall(context); continue; } } return(response); }
public static UpdateEntityResponse Unmarshall(UnmarshallerContext context) { UpdateEntityResponse updateEntityResponse = new UpdateEntityResponse(); updateEntityResponse.HttpResponse = context.HttpResponse; updateEntityResponse.RequestId = context.StringValue("UpdateEntity.RequestId"); updateEntityResponse.EntityId = context.StringValue("UpdateEntity.EntityId"); return(updateEntityResponse); }
public void CheckAndUpdateEntity(string entity, OrganizationWebProxyClient proxy, Logger logger) { var checkRequest = new RetrieveEntityRequest() { LogicalName = entity, EntityFilters = EntityFilters.Entity }; RetrieveEntityResponse checkResponse = (RetrieveEntityResponse)proxy.Execute(checkRequest); // Check if entity exists if (checkResponse == null || checkResponse.EntityMetadata == null) { logger.LogCustomProperty("PSAEntity", $"The {entity} entity cannot be retrieved from the PSA instance."); throw new Exception($"The {entity} entity cannot be retrieved from the PSA instance."); } // Check if change tracking enabled if (!(bool)checkResponse.EntityMetadata.ChangeTrackingEnabled) { // Check if change tracking can be enabled if (!checkResponse.EntityMetadata.CanChangeTrackingBeEnabled.Value) { logger.LogCustomProperty("PSAEntity", $"The {entity} entity cannot be enabled for change tracking."); throw new Exception($"The {entity} entity cannot be enabled for change tracking."); } else { UpdateEntityRequest updateRequest = new UpdateEntityRequest() { Entity = checkResponse.EntityMetadata }; updateRequest.Entity.ChangeTrackingEnabled = true; UpdateEntityResponse updateResponse = (UpdateEntityResponse)proxy.Execute(updateRequest); // Check the entity has actually been change tracking enabled RetrieveEntityResponse verifyChange = (RetrieveEntityResponse)proxy.Execute(checkRequest); if (!(bool)verifyChange.EntityMetadata.ChangeTrackingEnabled) { logger.LogCustomProperty("PSAEntity", $"Warning: Change tracking for {entity} has been enabled, but is not yet active."); } } } }
public bool CheckAndUpdateEntity(string entity, OrganizationWebProxyClient proxy, Logger logger) { var checkRequest = new RetrieveEntityRequest() { LogicalName = entity, EntityFilters = EntityFilters.Entity }; var checkResponse = new RetrieveEntityResponse(); checkResponse = (RetrieveEntityResponse)proxy.Execute(checkRequest); if (checkResponse.EntityMetadata.ChangeTrackingEnabled != null && !(bool)checkResponse.EntityMetadata.ChangeTrackingEnabled && checkResponse.EntityMetadata.CanChangeTrackingBeEnabled.Value) { var updateRequest = new UpdateEntityRequest() { Entity = checkResponse.EntityMetadata }; updateRequest.Entity.ChangeTrackingEnabled = true; var updateResponse = new UpdateEntityResponse(); updateResponse = (UpdateEntityResponse)proxy.Execute(updateRequest); return(true); } if (checkResponse.EntityMetadata.ChangeTrackingEnabled != null && (bool)checkResponse.EntityMetadata.ChangeTrackingEnabled) { return(true); } return(false); }
public void UpdateEntityData(BackgroundWorker w, bool bCountMode) { iEntityCount = 0; iEntityUpdatedCount = 0; iAttributeCount = 0; iAttributeUpdatedCount = 0; if (bCountMode) //if this is count mode then initialise counter { iEntitiesOrAttributesToUpdate = 0; } LogInfo("Apply updates to CRM (if any)"); foreach (string sKey in FileEntitySet.entities.Keys) //loop over entities read from file { iEntityCount++; if (CRMEntitySet.entities.ContainsKey(sKey)) //only do this if there is a corresponding entity in CRM - should almost always be so { if (RemoveNulls(FileEntitySet.entities[sKey].GetTaggedDescription(mySettings.UseTags, mySettings.TagOpeningString, mySettings.TagClosingString)) != RemoveNulls(CRMEntitySet.entities[sKey].GetTaggedDescription(mySettings.UseTags, mySettings.TagOpeningString, mySettings.TagClosingString))) { //Entity description has changed so update it unless not updateable if (!CRMEntitySet.entities[sKey].NotUpdateAble) { if (bCountMode) { iEntitiesOrAttributesToUpdate++; } else { string sDescription = FileEntitySet.entities[sKey].GetTaggedDescription(mySettings.UseTags, mySettings.TagOpeningString, mySettings.TagClosingString); LogInfo2(string.Format("About to update entity {0} with description {1}", sKey, sDescription)); EntityMetadata entityMeta = new EntityMetadata() { LogicalName = sKey, Description = new Microsoft.Xrm.Sdk.Label(sDescription, FileEntitySet.entities[sKey].LanguageCode) }; UpdateEntityRequest UpdateRequest = new UpdateEntityRequest() { Entity = entityMeta }; UpdateEntityResponse updateResp = (UpdateEntityResponse)Service.Execute(UpdateRequest); iEntityUpdatedCount++; w.ReportProgress(-1, "Entity/attribute updated. Completed: " + ((iAttributeUpdatedCount + iEntityUpdatedCount) * 100 / iEntitiesOrAttributesToUpdate).ToString() + "%"); } } else { LogWarning("Entity description for " + sKey + " could not be updated as this is not permitted by CRM"); } } foreach (string sKey2 in FileEntitySet.entities[sKey].attributes.Keys) { iAttributeCount++; if (CRMEntitySet.entities[sKey].attributes.ContainsKey(sKey2)) //only do this if attribute present { if (!CRMEntitySet.entities[sKey].attributes[sKey2].NotUpdateAble) //skip if not updateable { if (RemoveNulls(FileEntitySet.entities[sKey].attributes[sKey2].GetTaggedDescription(mySettings.UseTags, mySettings.TagOpeningString, mySettings.TagClosingString)) != RemoveNulls(CRMEntitySet.entities[sKey].attributes[sKey2].GetTaggedDescription(mySettings.UseTags, mySettings.TagOpeningString, mySettings.TagClosingString))) { if (bCountMode) { iEntitiesOrAttributesToUpdate++; } else { string sDescription = FileEntitySet.entities[sKey].attributes[sKey2].GetTaggedDescription(mySettings.UseTags, mySettings.TagOpeningString, mySettings.TagClosingString); LogInfo2(string.Format("About to update attribute {0} in entity {1} with description {2}", sKey2, sKey, sDescription)); //Construct metadata. Note special for picklist if ((CRMEntitySet.entities[sKey].attributes[sKey2].attributeTypeDescription == "Picklist") && CRMEntitySet.entities[sKey].attributes[sKey2].DefaultOptionSetValue != null) //this shows that it is a picklist with non-default default { PicklistAttributeMetadata atttributeMeta = new PicklistAttributeMetadata() { LogicalName = sKey2, Description = new Microsoft.Xrm.Sdk.Label(sDescription, FileEntitySet.entities[sKey].attributes[sKey2].LanguageCode), DefaultFormValue = CRMEntitySet.entities[sKey].attributes[sKey2].DefaultOptionSetValue }; UpdateAttributeRequest UpdateRequest = new UpdateAttributeRequest() { Attribute = atttributeMeta, EntityName = sKey }; iAttributeUpdatedCount++; UpdateAttributeResponse updateResp = (UpdateAttributeResponse)Service.Execute(UpdateRequest); } else { AttributeMetadata atttributeMeta = new AttributeMetadata() { LogicalName = sKey2, Description = new Microsoft.Xrm.Sdk.Label(sDescription, FileEntitySet.entities[sKey].attributes[sKey2].LanguageCode) }; UpdateAttributeRequest UpdateRequest = new UpdateAttributeRequest() { Attribute = atttributeMeta, EntityName = sKey }; iAttributeUpdatedCount++; UpdateAttributeResponse updateResp = (UpdateAttributeResponse)Service.Execute(UpdateRequest); } w.ReportProgress(-1, "Entity/attribute updated. Completed: " + ((iAttributeUpdatedCount + iEntityUpdatedCount) * 100 / iEntitiesOrAttributesToUpdate).ToString() + "%"); } } } else { LogWarning("Skipping field " + sKey2 + " as not updateable"); } } else { LogWarning("Atttibute " + sKey2 + " in entity " + sKey + " from input file not found in CRM. This record will be ignored"); } } } else { LogWarning("Entity " + sKey + " from input file not found in CRM. This record will be ignored"); } } }