public async void Rollup() { RollupRequest <float> dataPoint = new RollupRequest <float>(); dataPoint.Metric = "bridge"; dataPoint.Timestamp = 1575022650; dataPoint.Value = 23.4f; dataPoint.Tags.Add("host", "YL-01-01"); dataPoint.Tags.Add("dc", "lga"); //dataPoint.Interval = "1h"; //dataPoint.Aggregator= "SUM"; //dataPoint.GroupByAggregator = "SUM"; var result = await apiClient.PostAsync <dynamic>("/api/rollup?summary", dataPoint); Console.WriteLine(result); }
/// <summary> /// Retrieve all the entity records that are related to the specified record. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.rolluprequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="recordId">Record Id</param> /// <param name="entityLogicalName">Record's entity logical name</param> /// <param name="query"> /// <see cref="QueryExpression"/> query for related records.</param> /// <param name="rollupTypeCode"> /// The <c>Rollup Type</c> (<see cref="RollupType"/> ) for the supported entities depends on the target entity type. /// <c>0 : None</c>, a rollup record is not requested. This member only retrieves the records that are directly related to a parent record. /// <c>1 : Related</c>, a rollup record is not requested. This member only retrieves the records that are directly related to a parent record /// <c>2 : Extended</c>, a rollup record that is directly related to a parent record and to any descendent record of a parent record, for example, children, grandchildren, and great-grandchildren records. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.rolluptype(v=crm.8).aspx /// </para> /// </param>. /// <returns> /// <seealso cref="EntityCollection"/> for related rollup data /// </returns> public EntityCollection Rollup(Guid recordId, string entityLogicalName, QueryExpression query, RollupType rollupTypeCode) { ExceptionThrow.IfGuidEmpty(recordId, "recordId"); ExceptionThrow.IfNullOrEmpty(entityLogicalName, "entityLogicalName"); ExceptionThrow.IfNull(query, "query"); ExceptionThrow.IfNullOrEmpty(query.EntityName, "query.EntityName"); string queryEntity = query.EntityName.ToLower().Trim(); List <string> supportedTargetList = new List <string>() { "account", "contact", "opportunity" }; if (!supportedTargetList.Contains(entityLogicalName.ToLower().Trim())) { ExceptionThrow.IfNotExpectedValue(entityLogicalName, "entityLogicalName", "", string.Format("'{0}' is not supported for this operation. For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.rolluprequest(v=crm.8).aspx", entityLogicalName)); } if (!RollupRequestSupportedEntityList().Contains(queryEntity)) { ExceptionThrow.IfNotExpectedValue(queryEntity, "Query.EntityName", "", string.Format("'{0}' is not supported for this operation. For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.rolluprequest(v=crm.8).aspx", queryEntity)); } if (!RollupRequestSupportedRollupCombinationList().Contains(new Tuple <string, string, RollupType>(queryEntity, entityLogicalName, rollupTypeCode))) { ExceptionThrow.IfNotExpectedValue(entityLogicalName, "entityLogicalName", "", string.Format("Target entity ('{0}') - Supported Entity ('{1}') - Rollup Type ('{2}') combination is not supported for this operation. For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.rolluprequest(v=crm.8).aspx", entityLogicalName, queryEntity, rollupTypeCode.ToString())); } RollupRequest request = new RollupRequest() { Target = new EntityReference(entityLogicalName, recordId), Query = query, RollupType = rollupTypeCode }; RollupResponse serviceResponse = (RollupResponse)this.OrganizationService.Execute(request); return(serviceResponse.EntityCollection); }
[STAThread] // Added to support UX static void Main(string[] args) { CrmServiceClient service = null; try { service = SampleHelpers.Connect("Connect"); if (service.IsReady) { #region Sample Code ////////////////////////////////////////////// #region Set up SetUpSample(service); #endregion Set up #region Demonstrate // Create QueryExpression QueryExpression query = new QueryExpression() { EntityName = Opportunity.EntityLogicalName, ColumnSet = new ColumnSet("name", "accountid"), Criteria = { Filters = { new FilterExpression { FilterOperator = LogicalOperator.And, Conditions = { new ConditionExpression("name", ConditionOperator.Equal, "Opportunity 1") }, } } }, }; Console.WriteLine("Created QueryExpression."); #endregion Create QueryExpression #region Create RollupRequest // Create RollupRequest RollupRequest rollupRequest = new RollupRequest(); rollupRequest.Query = query; rollupRequest.Target = new EntityReference("account", _accountId); rollupRequest.RollupType = RollupType.Extended; Console.WriteLine("Created RollupRequest."); #endregion Create RollupRequest #region Execute RollupRequest // Execute RollupRequest RollupResponse rollupResponse = (RollupResponse)service.Execute(rollupRequest); Console.WriteLine("Executed RollupRequest."); #endregion Execute RollupRequest #region Show RollupResponse results // Show RollupResponse results Console.WriteLine("RollupResponse Results:"); Console.WriteLine("--------------------------------------------------"); Console.WriteLine("Count: " + rollupResponse.Results.Count); for (int i = 0; i < rollupResponse.Results.Count; i++) { Console.WriteLine(); Console.WriteLine("LogicalName: " + rollupResponse.EntityCollection.Entities[i].LogicalName); Console.WriteLine("Id: " + rollupResponse.EntityCollection.Entities[i].Id); } #endregion Show RollupResponse results #region Clean up CleanUpSample(service); #endregion Clean up } #endregion Demonstrate else { const string UNABLE_TO_LOGIN_ERROR = "Unable to Login to Common Data Service"; if (service.LastCrmError.Equals(UNABLE_TO_LOGIN_ERROR)) { Console.WriteLine("Check the connection string values in cds/App.config."); throw new Exception(service.LastCrmError); } else { throw service.LastCrmException; } } } catch (Exception ex) { SampleHelpers.HandleException(ex); } finally { if (service != null) { service.Dispose(); } Console.WriteLine("Press <Enter> to exit."); Console.ReadLine(); } }
/// <summary> /// This sample demonstrates how to roll up opportunities by their parent account. /// The sample first creates the Rollup Request. Next, it executes that request. /// Finally, the sample displays the results of the Rollup Response. /// </summary> /// <param name="serverConfig">Contains server connection information.</param> /// <param name="promptforDelete">When True, the user will be prompted to delete all /// created entities.</param> public void Run(ServerConnection.Configuration serverConfig, bool promptforDelete) { try { // Connect to the Organization service. // The using statement assures that the service proxy will be properly disposed. using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,serverConfig.Credentials, serverConfig.DeviceCredentials)) { // This statement is required to enable early-bound type support. _serviceProxy.EnableProxyTypes(); CreateRequiredRecords(); #region Create QueryExpression // Create QueryExpression QueryExpression query = new QueryExpression() { EntityName = Opportunity.EntityLogicalName, ColumnSet = new ColumnSet("name", "accountid"), Criteria = { Filters = { new FilterExpression { FilterOperator = LogicalOperator.And, Conditions = { new ConditionExpression("name", ConditionOperator.Equal, "Opportunity 1") }, } } }, }; Console.WriteLine("Created QueryExpression."); #endregion Create QueryExpression #region Create RollupRequest //<snippetRollup1> // Create RollupRequest RollupRequest rollupRequest = new RollupRequest(); rollupRequest.Query = query; rollupRequest.Target = new EntityReference("account", _accountId); rollupRequest.RollupType = RollupType.Extended; Console.WriteLine("Created RollupRequest."); #endregion Create RollupRequest #region Execute RollupRequest // Execute RollupRequest RollupResponse rollupResponse = (RollupResponse)_serviceProxy.Execute(rollupRequest); Console.WriteLine("Executed RollupRequest."); //</snippetRollup1> #endregion Execute RollupRequest #region Show RollupResponse results // Show RollupResponse results Console.WriteLine("RollupResponse Results:"); Console.WriteLine("--------------------------------------------------"); Console.WriteLine("Count: " + rollupResponse.Results.Count); for (int i = 0; i < rollupResponse.Results.Count; i++ ) { Console.WriteLine(); Console.WriteLine("LogicalName: " + rollupResponse.EntityCollection.Entities[i].LogicalName); Console.WriteLine("Id: " + rollupResponse.EntityCollection.Entities[i].Id); } #endregion Show RollupResponse results DeleteRequiredRecords(promptforDelete); } } // Catch any service fault exceptions that Microsoft Dynamics CRM throws. catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>) { // You can handle an exception here or pass it back to the calling method. throw; } }
/// <summary> /// This sample demonstrates how to roll up opportunities by their parent account. /// The sample first creates the Rollup Request. Next, it executes that request. /// Finally, the sample displays the results of the Rollup Response. /// </summary> /// <param name="serverConfig">Contains server connection information.</param> /// <param name="promptforDelete">When True, the user will be prompted to delete all /// created entities.</param> public void Run(ServerConnection.Configuration serverConfig, bool promptforDelete) { try { // Connect to the Organization service. // The using statement assures that the service proxy will be properly disposed. using (_serviceProxy = ServerConnection.GetOrganizationProxy(serverConfig)) { // This statement is required to enable early-bound type support. _serviceProxy.EnableProxyTypes(); CreateRequiredRecords(); #region Create QueryExpression // Create QueryExpression QueryExpression query = new QueryExpression() { EntityName = Opportunity.EntityLogicalName, ColumnSet = new ColumnSet("name", "accountid"), Criteria = { Filters = { new FilterExpression { FilterOperator = LogicalOperator.And, Conditions = { new ConditionExpression("name", ConditionOperator.Equal, "Opportunity 1") }, } } }, }; Console.WriteLine("Created QueryExpression."); #endregion Create QueryExpression #region Create RollupRequest //<snippetRollup1> // Create RollupRequest RollupRequest rollupRequest = new RollupRequest(); rollupRequest.Query = query; rollupRequest.Target = new EntityReference("account", _accountId); rollupRequest.RollupType = RollupType.Extended; Console.WriteLine("Created RollupRequest."); #endregion Create RollupRequest #region Execute RollupRequest // Execute RollupRequest RollupResponse rollupResponse = (RollupResponse)_serviceProxy.Execute(rollupRequest); Console.WriteLine("Executed RollupRequest."); //</snippetRollup1> #endregion Execute RollupRequest #region Show RollupResponse results // Show RollupResponse results Console.WriteLine("RollupResponse Results:"); Console.WriteLine("--------------------------------------------------"); Console.WriteLine("Count: " + rollupResponse.Results.Count); for (int i = 0; i < rollupResponse.Results.Count; i++) { Console.WriteLine(); Console.WriteLine("LogicalName: " + rollupResponse.EntityCollection.Entities[i].LogicalName); Console.WriteLine("Id: " + rollupResponse.EntityCollection.Entities[i].Id); } #endregion Show RollupResponse results DeleteRequiredRecords(promptforDelete); } } // Catch any service fault exceptions that Microsoft Dynamics CRM throws. catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ) { // You can handle an exception here or pass it back to the calling method. throw; } }