Using the Search method to find projects is a great way to filter and return projects. Another advanced feature is to search projects based off custom item values. Below, we have a snippet to creates CustomFieldReportInputs (a collection) and a CustomFieldReportInputValue object that defines the type of custom value you're trying to search for.

	

CustomFieldReportInputs projectCFRI = new CustomFieldReportInputs();	 //A collection of custom inputs		
CustomFieldReportInputValue cfriv = new CustomFieldReportInputValue(); //The custom field report value container
cfriv.CustomFieldDefinitionId = new Guid("23f05015-cec2-4088-a606-a7cd25f172af"); //The GUID of the custom field object			
cfriv.Int32Value = 99; //The value of the custom field looking up (decimal type)
cfriv.TextValue = "99"; //The value of the custom field looking up (text value within a textbox control or string type)
cfriv.StringValue = "99"; //The value of the custom field looking up (string type)
projectCFRI.Inputs.Add(cfriv); //Include in the collection

//Create a collections object to return projects and pass in parameters as needed
List projects = client.Project.Search(
	userId:null, 
	orderBy:"", 
	sortDirection:0, 
	searchText:"", 
	createdStartTimeUTC:null, 
	createdEndTimeUTC:null, 
	updatedStartDateTimeUTC:null, 
	updatedEndDateTimeUTC:null, 
	scheduledStartDateTimeUTC:null, 
	scheduledEndDateTimeUTC:null, 
	startDateTimeUTC:null, 
	endDateTimeUTC:null, 
	dateRangeFilterType:null, 
	companyList:null, 
	companyContractList:null,
	isCompaniesMustBeAssociatedToProjectAsDefault: false,
	isCompanyContractsMustBeAssociatedToProjectAsDefault: false,
	projectStatusList:null,
	projectStatusReportList:null, 
	projectTypeList:null, 
	isActive:true, 
	isArchive:false, 
	isPlanning:false, 
	isTemplate:false, 
	isToBeDeleted:false, 
	departmentList:null, 
	groupList:null,
	userList:null,
	projectManagerList:null,
	primaryProjectManagerList:null,
	projectSponsorList:null,
	projectReportTypeList:"",
	isReportTypeLogicalAnd:false,
	poNumber:"",
	customerName:"",
	clientJobNumber:"",
	statusDescription:"",
	projectNumber:"",
	projectList:"",
	masterFolderList:"",
	planningProjectList:"",
	projectCustomFieldReportInputs: projectCFRI,
	includeProjectsWithTimeAndExpenseEntriesWithinDateRange:true,
	timeAndExpenseStartDate:null,
	timeAndExpenseEndDate:null,
	modelProperties: props);



This snippet shows how the model properties object can be used to return "ProjectResources" (a field that isn't returned by the model by default) as well as the default properties on the model. Click here for more details.

	
     
ModelProperties props = new ModelProperties();
props.AddModelPropertyList("default,ProjectResources");

// get active projects
List listProjects = client.Project.Search(
	userId: null,
	orderBy: "",
	sortDirection: 0,
	searchText: "Hello World",
	createdStartTimeUTC: null,
	createdEndTimeUTC: null,
	updatedStartDateTimeUTC: null,
	updatedEndDateTimeUTC: null,
	scheduledStartDateTimeUTC: null,
	scheduledEndDateTimeUTC: null,
	startDateTimeUTC: null,
	endDateTimeUTC: null,
	dateRangeFilterType: null,
	companyList: null,
	companyContractList: null,
	isCompaniesMustBeAssociatedToProjectAsDefault: false,
	isCompanyContractsMustBeAssociatedToProjectAsDefault: false,
	projectStatusList: null,
	projectStatusReportList: null,
	projectTypeList: null,
	isActive: true,
	isArchive: false,
	isPlanning: false,
	isTemplate: false,
	isToBeDeleted: false,
	departmentList: null,
	groupList: null,
	userList: null,
	projectManagerList: null,
	primaryProjectManagerList: null,
	projectSponsorList: null,
	projectReportTypeList: "",
	isReportTypeLogicalAnd: false,
	poNumber: "",
	customerName: "",
	clientJobNumber: "",
	statusDescription: "",
	projectNumber: "",
	projectList: "",
	masterFolderList: "",
	planningProjectList: "",
	projectCustomFieldReportInputs: null,
	includeProjectsWithTimeAndExpenseEntriesWithinDateRange: true,
	timeAndExpenseStartDate: null,
	timeAndExpenseEndDate: null,
	modelProperties: props);

// loop through projects
foreach (ProjectInsight.Models.Projects.Project p in listProjects)
{
	// loop through resources to find project manager
	if (p.ProjectResources != null)
	{
		foreach (ProjectInsight.Models.Projects.ProjectResource resource in p.ProjectResources)
		{
			if (resource.IsProjectManager.HasValue)
			{
				// do something
			}
		}
	}				
}

This last example shows a more advanced way to return a list and/or collection of object models from a project. Note: selecting tasks from a task collection is used to "recursively" find retrieve other items, such as task summaries.

	
     
ModelProperties props = new ModelProperties();
props.AddModelPropertyList("projectresources,tasks;projectresource:isprojectmanager,actualhours;task:issummarytask,name,tasks");

// get active projects
List listProjects = client.Project.Search(
	userId: null,
	orderBy: "",
	sortDirection: 0,
	searchText: "Darth Star Plans",
	createdStartTimeUTC: null,
	createdEndTimeUTC: null,
	updatedStartDateTimeUTC: null,
	updatedEndDateTimeUTC: null,
	scheduledStartDateTimeUTC: null,
	scheduledEndDateTimeUTC: null,
	startDateTimeUTC: null,
	endDateTimeUTC: null,
	dateRangeFilterType: null,
	companyList: null,
	companyContractList: null,
	isCompaniesMustBeAssociatedToProjectAsDefault: false,
	isCompanyContractsMustBeAssociatedToProjectAsDefault: false,
	projectStatusList: null,
	projectStatusReportList: null,
	projectTypeList: null,
	isActive: true,
	isArchive: false,
	isPlanning: false,
	isTemplate: false,
	isToBeDeleted: false,
	departmentList: null,
	groupList: null,
	userList: null,
	projectManagerList: null,
	primaryProjectManagerList: null,
	projectSponsorList: null,
	projectReportTypeList: "",
	isReportTypeLogicalAnd: false,
	poNumber: "",
	customerName: "",
	clientJobNumber: "",
	statusDescription: "",
	projectNumber: "",
	projectList: "",
	masterFolderList: "",
	planningProjectList: "",
	projectCustomFieldReportInputs: null,
	includeProjectsWithTimeAndExpenseEntriesWithinDateRange: true,
	timeAndExpenseStartDate: null,
	timeAndExpenseEndDate: null,
	modelProperties: props);

// Check if a project is returned
if (listProjects.Count == 1)
{
	if (listProjects[0].Tasks != null)
	{
		// loop through tasks
		foreach (ProjectInsight.Models.Tasks.Task t1 in listProjects[0].Tasks)
		{
			if (t1.IsSummaryTask == true)
			{
				if (t1.Tasks != null)  // this is always null
				{
					// loop through first-level child tasks
					foreach (ProjectInsight.Models.Tasks.Task t2 in t1.Tasks)
					{
						// do something
					}
				}
			}
		}
	}
}

Online 11/27/2017