SearchRecords Method

This function is used to retrieve content from the Agility UGC content store. Use this function to retrieve content of all types and user information for your Website Users. SearchRecords allows for paging through a result set of any records within a given User Generated Content Definition or Website User Type.  

Parameters

Parameter  Description 
 Auth (DataServiceAuthorization) This object can be retrieved from the DataServiceUtil class in the API dll.
 searchArg (RecordSearchArg) Object of type Agility.UGC.API.SearchArg
PageSize = 20 The page size.  0 will return the max page size, 1000.
RecordOffset = 0 The first record to start returning results from.
SortedField = "" The field name to sort the results by. This may be any field defined on the User Generated Content definition in the RecordType, or any of the following built-in values: CreatedOn, ModifiedOn.
SortDirection = ""
  • String
  • ASC or DESC.
  • RecordTypeName = “<User Generated Content Definition Reference Name>” OR “<Website User Type Reference Name>”
  • String
  • The reference name of the User Generated Content Definition or Website User Type as configured in Agility.
  •  Search = "
    • The search query
    • Can be in the following format:
    • FieldName1 = ‘StringValue’ &&  (FieldName2 > NumValX ||  FieldName2 < NumValY)
    • This query relies on the use of && (for AND) and || (for OR) and a space before and after each operator ( = ,  < , > ,  LIKE ).   
    • Brackets may be used, but not nested.  
    • To filter using dates, you must provide them in "yyyy-MM-dd" format. For example, "MyDateProperty > '2011-01-31'".
    • SQL inject attempts will return an error.
    • In addition to fields you have added to the record type definition, you may also search using the ID, ModifiedOn, ModeratedOn, AbuseCount, CreatedByRecordID, ModifiedByRecordID, and ModeratedByRecordID fields as criteria.
    CacheKey = ""
    • Optional
    • The custom cache key.
    • Using this ensures that any search results that have been accessed using this cache key will be cleared as a group when SaveRecords is called with this cacheKey included as a parameter, or when ClearCache is called with this cacheKey as a parameter.

    Returns

    • PagedResult object
      • TotalRecords
        • Integer – the total number of records that matched the search
      • List<Record> – Records
        • The current page of data in the result set as an array of record objects
        • See the Introduction section for a description of the Record object

    Usage

    SearchRecords is used any time data is retrieved from the Agility UGC content store.  For example, listing records, populating dropdown menus, searching for specific content, and any situation where you need to find a record in UGC based on a User Generated Content Definition or Website User Type. Please note that SearchRecords does not return all metadata for File type fields and large text fields.  This additional metadata can be retrieved by the GetRecord() call.

    SearchRecords call in JavaScript

    //search for records in the "Profiles" Website User Type table
    //only return 10 records at a time
    //start at the beginning of the results
    //find record that have FirstName starting with Joe
    
    var searchArg = new Agility.UGC.API.SearchArg();
    searchArg.RecordTypeName = "Profile";
    searchArg.PageSize = 10; 
    searchArg.RecordOffset= 0; 
    searchArg.Search = "FirstName LIKE 'Joe%'";		
    
    //if the data should be cached based on a custom key...
    searchAry.CacheKey = "MyCustomCacheKey"; //TODO: calculate this key value, and only use if necessary.
    
    //invoke the SearchRecords method, which is asynchronous, and has a callback
    Agility.UGC.API.SearchRecords(searchArg, function(data) {	
    	
    	if (data.ResponseType != Agility.UGC.API.ResponseType.OK) {
    		//error occurred
    		alert("An error occurred: " + data.Message);			
    	} else {
    		//data.ResponseData is a "PagedResult" object 
    		//with Records and TotalRecords properties.
    		var records = data.ResponseData.Records;
    		var totalRecords= data.Response.TotalRecords;
    		
    		//get the firstname and lastname 
    		//properties of the first record...
    		var firstName = records[0].FirstName;
    		var lastName = records[0].LastName;		
    	}
    }
                        

    SearchRecords call in C#

    //search for records in the "Profiles" Website User Type table
    //only return 10 records at a time
    //start at the beginning of the results
    //find record that have FirstName starting with Joe
    
    using (Agility_UGC_API_WCFClient client = DataServiceUtil.GetUGCClient())
    {
       DataServiceAuthorization auth =
         DataServiceUtil.GetDataServiceAuthorization(-1);
    					
        //build the search argument
       RecordSearchArg arg = new RecordSearchArg() {
          RecordTypeName = " Profile ",
    	Search = "FirstName LIKE 'Joe%'",
          PageSize = 10,
    	RecordOffset = 0					
       };
    
    //if the data should be cached based on a custom key...
    arg.CacheKey = "MyCustomCacheKey"; //TODO: calculate this key value, and only use if necessary.
    
    
       
       PagedResult result = client.SearchRecords(auth, arg);
    
    
       int count = result.TotalRecords; searchArg.RecordTypeName = "Profile";
       //get the firstname and lastname 
       //properties of the first record...
       var firstName = records[0]["FirstName"];
       var lastName = records[0]["LastName"];
    }
                        

    SearchRecords call in PHP

    //search for records in the "Profiles" Website User Type table
    //only return 10 records at a time
    //start at the beginning of the results
    //find records that have FirstName starting with Joe
    
    PageSize = 10;
    	$searchArg->RecordTypeName = "Profiles";
    	$searchArg->RecordOffset = 0;
    	$searchArg->Search = "FirstName LIKE 'Joe%'";
    	
    	$results = $client->SearchRecords($searchArg);
    		
    		
    		if($results->TotalRecords > 0)
    		{
    			echo "Records were returned”;
    
    			echo “Here is the first name of the first record - ”;
    			echo $results->Records[0][“FirstName”]
    		}
    		else
    		{
    			echo “No records found with the provided search criteria”;
    		}
            
      ?>
                        

    LOGIN

    Log in with your Agility username and password or
    register for the site




    Log In

    REGISTER












    Register

    FORGOT PASSWORD