AX2012 Date Ranges using Query Service

Before using this sample please refer this link that which I posted earlier.
http://krishhdax.blogspot.com/2012/02/ax2012-consume-query-service.html 

public void krishh_QueryServiceDateRangeFilter()
   {
      QueryServiceClient client = new QueryServiceClient();
      DataSet dataSet;
      Paging paging = new ValueBasedPaging() { RecordLimit = 1000 };
      QueryMetadata query;
      QueryDataSourceMetadata employeeDataSource;
      QueryDataRangeMetadata employeeRange;
      query = new QueryMetadata();
      // Set the properties of the query.
      query.QueryType = QueryType.Join;
      query.DataSources = new QueryDataSourceMetadata[1];
      // Set the properties of the EmployeeDataSource
      employeeDataSource = new QueryDataSourceMetadata();
      employeeDataSource.Name = "Employee";
      employeeDataSource.Enabled = true;
      employeeDataSource.Table = "HcmEmployment";
      //This property will set for Dataset to Retrieve all fields 
      employeeDataSource.DynamicFieldList = true;   
      // Add the data source to the query
      query.DataSources[0] = employeeDataSource;
      // filter for active employees only
      employeeRange = new QueryDataRangeMetadata();
      employeeRange.TableName = "HcmEmployment";
      employeeRange.FieldName = "ValidTo";
      employeeRange.Value = "31/12/2154 11:59 PM";
      employeeRange.Enabled = true;
      employeeDataSource.Ranges = new QueryDataRangeMetadata[1];
      employeeDataSource.Ranges[0] = employeeRange;
      // Exeucte the Query and load the data into the Dataset
      dataSet = client.ExecuteQuery(query, ref paging);
     // load your dataset to your grid or gridview.
    }

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.