/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { // Get the PackageService. PackageService packageService = (PackageService) user.GetService(DfpService.v201505.PackageService); // Create a statement to only select packages that are in progress. StatementBuilder statementBuilder = new StatementBuilder() .Where("status = :status") .OrderBy("id ASC") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("status", PackageStatus.IN_PROGRESS.ToString()); // Set default for page. PackagePage page = new PackagePage(); try { do { // Get packages by statement. page = packageService.getPackagesByStatement(statementBuilder.ToStatement()); if (page.results != null && page.results.Length > 0) { int i = page.startIndex; foreach (Package package in page.results) { Console.WriteLine("{0}) Package with ID = \"{1}\", name = \"{2}\" for proposal ID " + "\"{3}\" was found.", i++, package.id, package.name, package.proposalId); } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while(statementBuilder.GetOffset() < page.totalResultSetSize); Console.WriteLine("Number of results found: " + page.totalResultSetSize); } catch (Exception ex) { Console.WriteLine("Failed to get packages. Exception says \"{0}\"", ex.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { // Get the PackageService. PackageService packageService = (PackageService) user.GetService(DfpService.v201505.PackageService); // Set the ID of the package to create line items from. long packageId = long.Parse(_T("INSERT_PACKAGE_ID_HERE")); // Create statement to select the package. StatementBuilder statementBuilder = new StatementBuilder() .Where("id = :id") .OrderBy("id ASC") .Limit(1) .AddValue("id", packageId); // Set default for page. PackagePage page = new PackagePage(); List<string> packageIds = new List<string>(); int i = 0; try { // Get the package. page = packageService.getPackagesByStatement(statementBuilder.ToStatement()); Package package = page.results[0]; Console.WriteLine("Package with ID \"{0}\" will create proposal line items using " + "product package with ID \"{1}\"", package.id, package.productPackageId); // Modify statement for action. statementBuilder.RemoveLimitAndOffset(); // Create action. CreateProposalLineItemsFromPackages action = new CreateProposalLineItemsFromPackages(); // Perform action. UpdateResult result = packageService.performPackageAction(action, statementBuilder.ToStatement()); // Display results. if (result != null && result.numChanges > 0) { Console.WriteLine("Proposal line items were created for {0} packages.", result.numChanges); } else { Console.WriteLine("No proposal line items were created."); } } catch (Exception ex) { Console.WriteLine("Failed to create proposal line items. Exception says \"{0}\"", ex.Message); } }