/// <summary> /// This method creates any entity records that this sample requires. /// Create a unit group. /// Retrieve the default unit. /// Create few products. /// Create new discount list and discount. /// Create new price list and few price list items. /// Create an account record. /// Create a new opportunity and few opportunity products. /// </summary> public void CreateRequiredRecords() { // Create a unit group UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); Console.WriteLine("Created {0}", newUnitGroup.Name); // Retrieve the default unit id that was automatically created // when we created the Unit Group QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "uomscheduleid", Operator = ConditionOperator.Equal, Values = { _unitGroupId } } } }, PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; // Retrieve the unit. UoM unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; _defaultUnitId = unit.UoMId.Value; Console.WriteLine("Retrieved {0}", unit.Name); // Create a few products Product newProduct1 = new Product { ProductNumber = "1", Name = "Example Product 1", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _product1Id = _serviceProxy.Create(newProduct1); Console.WriteLine("Created {0}", newProduct1.Name); Product newProduct2 = new Product { ProductNumber = "2", Name = "Example Product 2", ProductStructure = new OptionSetValue(1), QuantityDecimal = 3, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _product2Id = _serviceProxy.Create(newProduct2); Console.WriteLine("Created {0}", newProduct2.Name); // Create a new discount list DiscountType newDiscountType = new DiscountType { Name = "Example Discount List", IsAmountType = false }; _discountTypeId = _serviceProxy.Create(newDiscountType); Console.WriteLine("Created {0}", newDiscountType.Name); // Create a new discount Discount newDiscount = new Discount { DiscountTypeId = new EntityReference(DiscountType.EntityLogicalName, _discountTypeId), LowQuantity = 5, HighQuantity = 10, Percentage = 3 }; _discountId = _serviceProxy.Create(newDiscount); Console.WriteLine("Created new discount for the {0}.", newDiscountType.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); Console.WriteLine("Created {0}", newPriceList.Name); // Create a price list item for the first product and apply volume discount ProductPriceLevel newPriceListItem1 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(20), DiscountTypeId = new EntityReference(DiscountType.EntityLogicalName, _discountTypeId) }; _priceListItem1Id = _serviceProxy.Create(newPriceListItem1); Console.WriteLine(@"Created price list item for the {0} and applied volume discount.", newProduct1.Name); // Create a price list item for the second product ProductPriceLevel newPriceListItem2 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(20) }; _priceListItem2Id = _serviceProxy.Create(newPriceListItem2); Console.WriteLine("Created price list item for the {0}.", newProduct1.Name); //Publish Product1 SetStateRequest publishRequest1 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product1Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest1); //Publish Product2 SetStateRequest publishRequest2 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product2Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest2); Console.WriteLine("Published both the products"); // Create an account record for the opporutnity's potential customerid Account newAccount = new Account { Name = "Example Account" }; _accountId = _serviceProxy.Create(newAccount); Console.WriteLine("Created {0}", newAccount.Name); // Create a new opportunity Opportunity newOpportunity = new Opportunity { Name = "Example Opportunity", CustomerId = new EntityReference(Account.EntityLogicalName, _accountId), PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId) }; _opportunityId = _serviceProxy.Create(newOpportunity); Console.WriteLine("Created {0}.", newOpportunity.Name); // Create some opportunity products OpportunityProduct newOpportunityProduct1 = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Quantity = 8 }; _opportunityProduct1Id = _serviceProxy.Create(newOpportunityProduct1); OpportunityProduct newOpportunityProduct2 = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Quantity = 1 }; _opportunityProduct2Id = _serviceProxy.Create( newOpportunityProduct2); Console.WriteLine("Created few opportunity products."); return; }
/// <summary> /// This method creates any entity records that this sample requires. /// Create a unit group and price list. /// </summary> public void CreateRequiredRecords() { Console.WriteLine("Creating required records for the sample:"); // Create a unit group. UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); Console.WriteLine("Created {0}", newUnitGroup.Name); // retrieve the unit id. QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression(), PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; unitQuery.Criteria.AddCondition("uomscheduleid", ConditionOperator.Equal, _unitGroupId); // Retrieve the unit. unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; Console.WriteLine("Retrieved {0}", unit.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); Console.WriteLine("Created {0}", newPriceList.Name); // Create couple of product records Product newProduct1 = new Product { Name = "Example Product 1", ProductNumber = "P001", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, unit.Id) }; _product1Id = _serviceProxy.Create(newProduct1); Console.WriteLine("\nCreated {0}", newProduct1.Name); Product newProduct2 = new Product { Name = "Example Product 2", ProductNumber = "P002", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, unit.Id) }; _product2Id = _serviceProxy.Create(newProduct2); Console.WriteLine("Created {0}", newProduct2.Name); // Create price list items for the products ProductPriceLevel newPriceListItem1 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Amount = new Money(20) }; _priceListItem1Id = _serviceProxy.Create(newPriceListItem1); Console.WriteLine("Created price list for {0}", newProduct1.Name); ProductPriceLevel newPriceListItem2 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Amount = new Money(20) }; _priceListItem2Id = _serviceProxy.Create(newPriceListItem2); Console.WriteLine("Created price list for {0}", newProduct2.Name); Product newBundle = new Product { Name = "Example Bundle", ProductNumber = "B001", ProductStructure = new OptionSetValue(3), QuantityDecimal = 0, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, unit.Id) }; _bundleId = _serviceProxy.Create(newBundle); Console.WriteLine("\nCreated {0}", newBundle.Name); // Create price list item for the bundle ProductPriceLevel newPriceListItem3 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _bundleId), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Amount = new Money(200) }; _priceListItem3Id = _serviceProxy.Create(newPriceListItem3); Console.WriteLine("Created price list for {0}", newBundle.Name); return; }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { #region create kb articles Console.WriteLine(" Creating KB Articles"); _subjectId = ( from subject in _context.SubjectSet where subject.Title == "Default Subject" select subject.Id ).First(); var kbArticleTemplateId = ( from articleTemplate in _context.KbArticleTemplateSet where articleTemplate.Title == "Standard KB Article" select articleTemplate.Id ).FirstOrDefault(); if (kbArticleTemplateId != Guid.Empty) { // create a KB article _articles[0] = new KbArticle() { // set the article properties Title = "Searching the knowledge base", ArticleXml = @" <articledata> <section id='0'> <content><![CDATA[This is a sample article about searching the knowledge base.]]></content> </section> <section id='1'> <content><![CDATA[Knowledge bases contain information useful for various people.]]></content> </section> </articledata>", // use the built-in "Standard KB Article" template KbArticleTemplateId = new EntityReference(KbArticleTemplate.EntityLogicalName, kbArticleTemplateId), // use the default subject SubjectId = new EntityReference(Subject.EntityLogicalName, _subjectId), KeyWords = "Searching Knowledge base" }; _context.AddObject(_articles[0]); _articles[1] = new KbArticle() { Title = "What's in a knowledge base", ArticleXml = @" <articledata> <section id='0'> <content><![CDATA[This is a sample article about what would be in a knowledge base.]]></content> </section> <section id='1'> <content><![CDATA[This section contains more information.]]></content> </section> </articledata>", KbArticleTemplateId = new EntityReference(KbArticleTemplate.EntityLogicalName, kbArticleTemplateId), SubjectId = new EntityReference(Subject.EntityLogicalName, _subjectId), KeyWords = "Knowledge base" }; _context.AddObject(_articles[1]); _articles[2] = new KbArticle() { Title = "Searching the knowledge base from code", ArticleXml = @" <articledata> <section id='0'> <content><![CDATA[This article covers searching the knowledge base from code.]]></content> </section> <section id='1'> <content><![CDATA[This section contains more information.]]></content> </section> </articledata>", KbArticleTemplateId = new EntityReference(KbArticleTemplate.EntityLogicalName, kbArticleTemplateId), SubjectId = new EntityReference(Subject.EntityLogicalName, _subjectId), KeyWords = "Knowledge base code" }; _context.AddObject(_articles[2]); _context.SaveChanges(); } else { throw new ArgumentException("Standard Article Templates are missing"); } #endregion #region Submit the articles Console.WriteLine(" Submitting the articles"); foreach (var article in _articles) { _context.Execute(new SetStateRequest { EntityMoniker = article.ToEntityReference(), State = new OptionSetValue((int)KbArticleState.Unapproved), Status = new OptionSetValue((int)kbarticle_statuscode.Unapproved) }); } #endregion #region Approve and Publish the article Console.WriteLine(" Publishing articles"); foreach (var article in _articles) { _context.Execute(new SetStateRequest { EntityMoniker = article.ToEntityReference(), State = new OptionSetValue((int)KbArticleState.Published), Status = new OptionSetValue((int)kbarticle_statuscode.Published) }); } #endregion #region Waiting for publishing to finish // Wait 20 seconds to ensure that data will be available // Full-text indexing Console.WriteLine(" Waiting 20 seconds to ensure indexing has completed on the new records."); System.Threading.Thread.Sleep(20000); Console.WriteLine(); #endregion #region Add cases to KbArticles // Create UoM _uomSchedule = new UoMSchedule() { Name = "Sample unit group", BaseUoMName = "Sample base unit" }; _context.AddObject(_uomSchedule); _context.SaveChanges(); _uom = (from uom in _context.UoMSet where uom.Name == _uomSchedule.BaseUoMName select uom).First(); Console.WriteLine(" Creating an account and incidents for the KB articles"); var whoami = (WhoAmIResponse)_context.Execute(new WhoAmIRequest()); _account = new Account() { Name = "Coho Winery", }; _context.AddObject(_account); _context.SaveChanges(); _product = new Product() { Name = "Sample Product", ProductNumber = "0", ProductStructure = new OptionSetValue(1), DefaultUoMScheduleId = _uomSchedule.ToEntityReference(), DefaultUoMId = _uom.ToEntityReference() }; _context.AddObject(_product); _context.SaveChanges(); // Publish Product SetStateRequest publishRequest = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product.Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _context.Execute(publishRequest); _incident = new Incident() { Title = "A sample incident", OwnerId = new EntityReference(SystemUser.EntityLogicalName, whoami.UserId), KbArticleId = _articles[0].ToEntityReference(), CustomerId = _account.ToEntityReference(), SubjectId = new EntityReference(Subject.EntityLogicalName, _subjectId), ProductId = _product.ToEntityReference() }; _context.AddObject(_incident); _context.SaveChanges(); #endregion }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { #region Create or Retrieve the necessary system users // Retrieve the ldapPath String ldapPath = String.Empty; // Retrieve the sales team - 1 sales manager and 2 sales representatives. _salesManagerId = SystemUserProvider.RetrieveSalesManager(_serviceProxy, ref ldapPath); _salesRepresentativeId = SystemUserProvider.RetrieveSalespersons(_serviceProxy, ref ldapPath)[0]; #endregion #region Create records to support SalesOrder records // Create a unit group UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); // Retrieve the default unit id that was automatically created // when we created the Unit Group QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "uomscheduleid", Operator = ConditionOperator.Equal, Values = { _unitGroupId } } } }, PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; // Retrieve the unit. UoM unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; _defaultUnitId = unit.UoMId.Value; // Create a few products Product newProduct = new Product { ProductNumber = "1", Name = "Example Product", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _productId = _serviceProxy.Create(newProduct); newProduct.Id = _productId; Console.WriteLine("Created {0}", newProduct.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); // Create a price list item for the first product and apply volume discount ProductPriceLevel newPriceListItem = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _productId), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(20), }; _priceListItemId = _serviceProxy.Create(newPriceListItem); // Publish the product SetStateRequest publishRequest = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _productId), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest); Console.WriteLine("Published {0}", newProduct.Name); // Create an account record for the sales order's potential customerid Account newAccount = new Account { Name = "Litware, Inc.", Address1_PostalCode = "60661" }; _accountId = _serviceProxy.Create(newAccount); newAccount.Id = _accountId; #endregion Create records to support SalesOrder #region Create SalesOrder record // Create the sales order. SalesOrder order = new SalesOrder() { Name = "Faux Order", DateFulfilled = new DateTime(2010, 8, 1), PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), CustomerId = new EntityReference(Account.EntityLogicalName, _accountId), FreightAmount = new Money(20.0M) }; _orderId = _serviceProxy.Create(order); order.Id = _orderId; // Add the product to the order with the price overriden with a // negative value. SalesOrderDetail orderDetail = new SalesOrderDetail() { ProductId = newProduct.ToEntityReference(), Quantity = 4, SalesOrderId = order.ToEntityReference(), IsPriceOverridden = true, PricePerUnit = new Money(1000.0M), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _orderDetailId = _serviceProxy.Create(orderDetail); #endregion Create SalesOrder record }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { #region Create or Retrieve the necessary system users // Retrieve the ldapPath String ldapPath = String.Empty; // Retrieve the sales team - 1 sales manager and 2 sales representatives. _salesManagerId = SystemUserProvider.RetrieveSalesManager(_serviceProxy, ref ldapPath); _salesRepresentativeIds = SystemUserProvider.RetrieveSalespersons(_serviceProxy, ref ldapPath); #endregion #region Create records to support Opportunity records // Create a unit group UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); // Retrieve the default unit id that was automatically created // when we created the Unit Group QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "uomscheduleid", Operator = ConditionOperator.Equal, Values = { _unitGroupId } } } }, PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; // Retrieve the unit. UoM unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; _defaultUnitId = unit.UoMId.Value; // Create a few products Product newProduct1 = new Product { ProductNumber = "1", Name = "Example Product 1", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _product1Id = _serviceProxy.Create(newProduct1); Console.WriteLine("Created {0}", newProduct1.Name); Product newProduct2 = new Product { ProductNumber = "2", Name = "Example Product 2", ProductStructure = new OptionSetValue(1), QuantityDecimal = 3, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _product2Id = _serviceProxy.Create(newProduct2); Console.WriteLine("Created {0}", newProduct2.Name); // Create a new discount list DiscountType newDiscountType = new DiscountType { Name = "Example Discount List", IsAmountType = false }; _discountTypeId = _serviceProxy.Create(newDiscountType); // Create a new discount Discount newDiscount = new Discount { DiscountTypeId = new EntityReference(DiscountType.EntityLogicalName, _discountTypeId), LowQuantity = 5, HighQuantity = 10, Percentage = 3 }; _discountId = _serviceProxy.Create(newDiscount); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); // Create a price list item for the first product and apply volume discount ProductPriceLevel newPriceListItem1 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(20), DiscountTypeId = new EntityReference(DiscountType.EntityLogicalName, _discountTypeId) }; _priceListItem1Id = _serviceProxy.Create(newPriceListItem1); // Create a price list item for the second product ProductPriceLevel newPriceListItem2 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(15) }; _priceListItem2Id = _serviceProxy.Create(newPriceListItem2); // Publish Product 1 SetStateRequest publishRequest1 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product1Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest1); // Publish Product 2 SetStateRequest publishRequest2 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product2Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest2); Console.WriteLine("Published {0} and {1}", newProduct1.Name, newProduct2.Name); // Create an account record for the opportunity's potential customerid Account newAccount = new Account { Name = "Litware, Inc.", Address1_PostalCode = "60661" }; _accountIds.Add(_serviceProxy.Create(newAccount)); newAccount = new Account { Name = "Margie's Travel", Address1_PostalCode = "99999" }; _accountIds.Add(_serviceProxy.Create(newAccount)); #endregion Create records to support Opportunity records #region Create Opportunity records // Create a new opportunity with user specified estimated revenue Opportunity newOpportunity = new Opportunity { Name = "Example Opportunity", CustomerId = new EntityReference(Account.EntityLogicalName, _accountIds[0]), PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), IsRevenueSystemCalculated = false, EstimatedValue = new Money(400.00m), FreightAmount = new Money(10.00m), DiscountAmount = new Money(0.10m), DiscountPercentage = 0.20m, ActualValue = new Money(400.00m), OwnerId = new EntityReference { Id = _salesRepresentativeIds[0], LogicalName = SystemUser.EntityLogicalName } }; _opportunityIds.Add(_serviceProxy.Create(newOpportunity)); Opportunity secondOpportunity = new Opportunity { Name = "Example Opportunity 2", CustomerId = new EntityReference(Account.EntityLogicalName, _accountIds[1]), PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), IsRevenueSystemCalculated = false, EstimatedValue = new Money(400.00m), FreightAmount = new Money(10.00m), DiscountAmount = new Money(0.10m), DiscountPercentage = 0.20m, ActualValue = new Money(400.00m), OwnerId = new EntityReference { Id = _salesRepresentativeIds[1], LogicalName = SystemUser.EntityLogicalName } }; _opportunityIds.Add(_serviceProxy.Create(secondOpportunity)); // Create a catalog product OpportunityProduct catalogProduct = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityIds[0]), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Quantity = 8, Tax = new Money(12.42m), }; _catalogProductId = _serviceProxy.Create(catalogProduct); // Create another catalog product and override the list price OpportunityProduct catalogProductPriceOverride = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityIds[1]), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Quantity = 3, Tax = new Money(2.88m), IsPriceOverridden = true, PricePerUnit = new Money(12) }; _catalogProductPriceOverrideId = _serviceProxy.Create( catalogProductPriceOverride); // create a new write-in opportunity product with a manual discount applied OpportunityProduct writeInProduct = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityIds[1]), IsProductOverridden = true, ProductDescription = "Example Write-in Product", PricePerUnit = new Money(20.00m), Quantity = 5, ManualDiscountAmount = new Money(10.50m), Tax = new Money(7.16m) }; _writeInProductId = _serviceProxy.Create(writeInProduct); // Close the opportunities as 'Won' WinOpportunityRequest winRequest = new WinOpportunityRequest() { OpportunityClose = new OpportunityClose() { OpportunityId = new EntityReference { Id = _opportunityIds[0], LogicalName = Opportunity.EntityLogicalName }, ActualRevenue = new Money(400.00M), ActualEnd = DateTime.Today }, Status = new OptionSetValue(3) }; _serviceProxy.Execute(winRequest); winRequest = new WinOpportunityRequest() { OpportunityClose = new OpportunityClose() { OpportunityId = new EntityReference { Id = _opportunityIds[1], LogicalName = Opportunity.EntityLogicalName }, ActualRevenue = new Money(400.00M), ActualEnd = DateTime.Today }, Status = new OptionSetValue(3) }; _serviceProxy.Execute(winRequest); #endregion Create Opportunity records }
/// <summary> /// This method creates any entity records that this sample requires. /// Create a unit group, few products, price list and price list items. /// Create an account record. /// Create few opportunities, opportunity products and a write-in product. /// </summary> public void CreateRequiredRecords() { // Create a unit group. UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); Console.WriteLine("Created {0}", newUnitGroup.Name); // retrieve the unit id. QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression(), PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; unitQuery.Criteria.AddCondition("uomscheduleid", ConditionOperator.Equal, _unitGroupId); // Retrieve the unit. UoM unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; Console.WriteLine("Retrieved {0}", unit.Name); // Create a few products Product newProduct1 = new Product { ProductNumber = "1", Name = "Example Product 1", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, unit.Id) }; _product1Id = _serviceProxy.Create(newProduct1); Console.WriteLine("Created {0}", newProduct1.Name); Product newProduct2 = new Product { ProductNumber = "2", Name = "Example Product 2", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, unit.Id) }; _product2Id = _serviceProxy.Create(newProduct2); Console.WriteLine("Created {0}", newProduct2.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); Console.WriteLine("Created {0}", newPriceList.Name); // Create a price list items for the products ProductPriceLevel newPriceListItem1 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Amount = new Money(20) }; _priceListItem1Id = _serviceProxy.Create(newPriceListItem1); Console.WriteLine("Created price list for {0}", newProduct1.Name); ProductPriceLevel newPriceListItem2 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Amount = new Money(20) }; _priceListItem2Id = _serviceProxy.Create(newPriceListItem2); Console.WriteLine("Created price list for {0}", newProduct2.Name); //Publish Product1 SetStateRequest publishRequest1 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product1Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest1); //Publish Product2 SetStateRequest publishRequest2 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product2Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest2); Console.WriteLine("Published both the products"); // Create an account record for the opportunity's potential customerid Account newAccount = new Account { Name = "Example Account" }; _accountId = _serviceProxy.Create(newAccount); Console.WriteLine("Created {0}", newAccount.Name); // Create a new opportunity Opportunity newOpportunity = new Opportunity { Name = "Example Opportunity", CustomerId = new EntityReference(Account.EntityLogicalName, _accountId), PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), FreightAmount = new Money(10.00m) }; _opportunityId = _serviceProxy.Create(newOpportunity); Console.WriteLine("Created {0}", newOpportunity.Name); // Create an opportunity product OpportunityProduct newOpportunityProduct1 = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Quantity = 3, Tax = new Money(4.80m) }; _opportunityProduct1Id = _serviceProxy.Create(newOpportunityProduct1); Console.WriteLine("Created opportunity product for {0} and {1}", newOpportunity.Name, newProduct1.Name); // Create a catalog product and override the price per unit OpportunityProduct newOpportunityProduct2 = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Quantity = 1, IsPriceOverridden = true, PricePerUnit = new Money(12), Tax = new Money(0.96m) }; _opportunityProduct2Id = _serviceProxy.Create(newOpportunityProduct2); Console.WriteLine("Created opportunity product for {0} and {1}", newOpportunity.Name, newProduct2.Name); // Create a write-in product with a manual discount OpportunityProduct newWriteInProduct = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityId), // set this attribute to make it a write-in product IsProductOverridden = true, ProductDescription = "Example Write-in Product", PricePerUnit = new Money(20.00m), Quantity = 5, ManualDiscountAmount = new Money(10.50m), Tax = new Money(7.16m) }; _writeInProductId = _serviceProxy.Create(newWriteInProduct); Console.WriteLine("Created {0}", newWriteInProduct.ProductDescription); return; }
/// <summary> /// This method creates any entity records that this sample requires. /// Create a unit group and price list. /// </summary> public void CreateRequiredRecords() { Console.WriteLine("Creating required records for the sample:"); // Create a unit group. UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); Console.WriteLine("Created {0}", newUnitGroup.Name); // retrieve the unit id. QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression(), PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; unitQuery.Criteria.AddCondition("uomscheduleid", ConditionOperator.Equal, _unitGroupId); // Retrieve the unit. _unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; Console.WriteLine("Retrieved {0}", _unit.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); Console.WriteLine("Created {0}", newPriceList.Name); return; }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { #region create kb articles Console.WriteLine(" Creating KB Articles"); _subjectId = ( from subject in _context.SubjectSet where subject.Title == "Default Subject" select subject.Id ).First(); var kbArticleTemplateId = ( from articleTemplate in _context.KbArticleTemplateSet where articleTemplate.Title == "Standard KB Article" select articleTemplate.Id ).FirstOrDefault(); if (kbArticleTemplateId != Guid.Empty) { // create a KB article _articles[0] = new KbArticle() { // set the article properties Title = "Searching the knowledge base", ArticleXml = @" <articledata> <section id='0'> <content><![CDATA[This is a sample article about searching the knowledge base.]]></content> </section> <section id='1'> <content><![CDATA[Knowledge bases contain information useful for various people.]]></content> </section> </articledata>", // use the built-in "Standard KB Article" template KbArticleTemplateId = new EntityReference(KbArticleTemplate.EntityLogicalName, kbArticleTemplateId), // use the default subject SubjectId = new EntityReference(Subject.EntityLogicalName, _subjectId), KeyWords = "Searching Knowledge base" }; _context.AddObject(_articles[0]); _articles[1] = new KbArticle() { Title = "What's in a knowledge base", ArticleXml = @" <articledata> <section id='0'> <content><![CDATA[This is a sample article about what would be in a knowledge base.]]></content> </section> <section id='1'> <content><![CDATA[This section contains more information.]]></content> </section> </articledata>", KbArticleTemplateId = new EntityReference(KbArticleTemplate.EntityLogicalName, kbArticleTemplateId), SubjectId = new EntityReference(Subject.EntityLogicalName, _subjectId), KeyWords = "Knowledge base" }; _context.AddObject(_articles[1]); _articles[2] = new KbArticle() { Title = "Searching the knowledge base from code", ArticleXml = @" <articledata> <section id='0'> <content><![CDATA[This article covers searching the knowledge base from code.]]></content> </section> <section id='1'> <content><![CDATA[This section contains more information.]]></content> </section> </articledata>", KbArticleTemplateId = new EntityReference(KbArticleTemplate.EntityLogicalName, kbArticleTemplateId), SubjectId = new EntityReference(Subject.EntityLogicalName, _subjectId), KeyWords = "Knowledge base code" }; _context.AddObject(_articles[2]); _context.SaveChanges(); } else { throw new ArgumentException("Standard Article Templates are missing"); } #endregion #region Submit the articles Console.WriteLine(" Submitting the articles"); foreach (var article in _articles) { _context.Execute(new SetStateRequest { EntityMoniker = article.ToEntityReference(), State = new OptionSetValue((int)KbArticleState.Unapproved), Status = new OptionSetValue((int)kbarticle_statuscode.Unapproved) }); } #endregion #region Approve and Publish the article Console.WriteLine(" Publishing articles"); foreach (var article in _articles) { _context.Execute(new SetStateRequest { EntityMoniker = article.ToEntityReference(), State = new OptionSetValue((int)KbArticleState.Published), Status = new OptionSetValue((int)kbarticle_statuscode.Published) }); } #endregion #region Waiting for publishing to finish // Wait 20 seconds to ensure that data will be available // Full-text indexing Console.WriteLine(" Waiting 20 seconds to ensure indexing has completed on the new records."); System.Threading.Thread.Sleep(20000); Console.WriteLine(); #endregion #region Add cases to KbArticles // Create UoM _uomSchedule = new UoMSchedule() { Name = "Sample unit group", BaseUoMName = "Sample base unit" }; _context.AddObject(_uomSchedule); _context.SaveChanges(); _uom = (from uom in _context.UoMSet where uom.Name == _uomSchedule.BaseUoMName select uom).First(); Console.WriteLine(" Creating an account and incidents for the KB articles"); var whoami = (WhoAmIResponse)_context.Execute(new WhoAmIRequest()); _account = new Account() { Name = "Coho Winery", }; _context.AddObject(_account); _context.SaveChanges(); _product = new Product() { Name = "Sample Product", ProductNumber = "0", ProductStructure = new OptionSetValue(1), DefaultUoMScheduleId = _uomSchedule.ToEntityReference(), DefaultUoMId = _uom.ToEntityReference() }; _context.AddObject(_product); _context.SaveChanges(); // Publish Product SetStateRequest publishRequest = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product.Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _context.Execute(publishRequest); _incident = new Incident() { Title = "A sample incident", OwnerId = new EntityReference(SystemUser.EntityLogicalName, whoami.UserId), KbArticleId = _articles[0].ToEntityReference(), CustomerId = _account.ToEntityReference(), SubjectId = new EntityReference(Subject.EntityLogicalName, _subjectId), ProductId = _product.ToEntityReference() }; _context.AddObject(_incident); _context.SaveChanges(); #endregion }
/// <summary> /// This method creates any entity records that this sample requires. /// Create a unit group. /// Retrieve the default unit. /// Create few products. /// Create new discount list and discount. /// Create new price list and few price list items. /// Create an account record. /// Create a new opportunity and few opportunity products. /// </summary> public void CreateRequiredRecords() { // Create a unit group UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); Console.WriteLine("Created {0}", newUnitGroup.Name); // Retrieve the default unit id that was automatically created // when we created the Unit Group QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "uomscheduleid", Operator = ConditionOperator.Equal, Values = { _unitGroupId } } } }, PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; // Retrieve the unit. UoM unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; _defaultUnitId = unit.UoMId.Value; Console.WriteLine("Retrieved {0}", unit.Name); // Create a few products Product newProduct1 = new Product { ProductNumber = "1", Name = "Example Product 1", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _product1Id = _serviceProxy.Create(newProduct1); Console.WriteLine("Created {0}", newProduct1.Name); Product newProduct2 = new Product { ProductNumber = "2", Name = "Example Product 2", ProductStructure = new OptionSetValue(1), QuantityDecimal = 3, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _product2Id = _serviceProxy.Create(newProduct2); Console.WriteLine("Created {0}", newProduct2.Name); // Create a new discount list DiscountType newDiscountType = new DiscountType { Name = "Example Discount List", IsAmountType = false }; _discountTypeId = _serviceProxy.Create(newDiscountType); Console.WriteLine("Created {0}", newDiscountType.Name); // Create a new discount Discount newDiscount = new Discount { DiscountTypeId = new EntityReference(DiscountType.EntityLogicalName, _discountTypeId), LowQuantity = 5, HighQuantity = 10, Percentage = 3 }; _discountId = _serviceProxy.Create(newDiscount); Console.WriteLine("Created new discount for the {0}.", newDiscountType.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); Console.WriteLine("Created {0}", newPriceList.Name); // Create a price list item for the first product and apply volume discount ProductPriceLevel newPriceListItem1 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(20), DiscountTypeId = new EntityReference(DiscountType.EntityLogicalName, _discountTypeId) }; _priceListItem1Id = _serviceProxy.Create(newPriceListItem1); Console.WriteLine(@"Created price list item for the {0} and applied volume discount.", newProduct1.Name); // Create a price list item for the second product ProductPriceLevel newPriceListItem2 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(20) }; _priceListItem2Id = _serviceProxy.Create(newPriceListItem2); Console.WriteLine("Created price list item for the {0}.", newProduct1.Name); //Publish Product1 SetStateRequest publishRequest1 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product1Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest1); //Publish Product2 SetStateRequest publishRequest2 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product2Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest2); Console.WriteLine("Published both the products"); // Create an account record for the opporutnity's potential customerid Account newAccount = new Account { Name = "Example Account" }; _accountId = _serviceProxy.Create(newAccount); Console.WriteLine("Created {0}", newAccount.Name); // Create a new opportunity Opportunity newOpportunity = new Opportunity { Name = "Example Opportunity", CustomerId = new EntityReference(Account.EntityLogicalName, _accountId), PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId) }; _opportunityId = _serviceProxy.Create(newOpportunity); Console.WriteLine("Created {0}.", newOpportunity.Name); // Create some opportunity products OpportunityProduct newOpportunityProduct1 = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Quantity = 8 }; _opportunityProduct1Id = _serviceProxy.Create(newOpportunityProduct1); OpportunityProduct newOpportunityProduct2 = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Quantity = 1 }; _opportunityProduct2Id = _serviceProxy.Create( newOpportunityProduct2); Console.WriteLine("Created few opportunity products."); return; }
/// <summary> /// This method creates any entity records that this sample requires. /// Create a unit group, few products, price list and price list items. /// Create an account record. /// Create few opportunities, opportunity products and a write-in product. /// </summary> public void CreateRequiredRecords() { // Create a unit group. UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); Console.WriteLine("Created {0}", newUnitGroup.Name); // retrieve the unit id. QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression(), PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; unitQuery.Criteria.AddCondition("uomscheduleid", ConditionOperator.Equal, _unitGroupId); // Retrieve the unit. UoM unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; Console.WriteLine("Retrieved {0}", unit.Name); // Create a few products Product newProduct1 = new Product { ProductNumber = "1", Name = "Example Product 1", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, unit.Id) }; _product1Id = _serviceProxy.Create(newProduct1); Console.WriteLine("Created {0}", newProduct1.Name); Product newProduct2 = new Product { ProductNumber = "2", Name = "Example Product 2", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, unit.Id) }; _product2Id = _serviceProxy.Create(newProduct2); Console.WriteLine("Created {0}", newProduct2.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); Console.WriteLine("Created {0}", newPriceList.Name); // Create a price list items for the products ProductPriceLevel newPriceListItem1 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Amount = new Money(20) }; _priceListItem1Id = _serviceProxy.Create(newPriceListItem1); Console.WriteLine("Created price list for {0}", newProduct1.Name); ProductPriceLevel newPriceListItem2 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Amount = new Money(20) }; _priceListItem2Id = _serviceProxy.Create(newPriceListItem2); Console.WriteLine("Created price list for {0}", newProduct2.Name); //Publish Product1 SetStateRequest publishRequest1 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product1Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest1); //Publish Product2 SetStateRequest publishRequest2 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product2Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest2); Console.WriteLine("Published both the products"); // Create an account record for the opportunity's potential customerid Account newAccount = new Account { Name = "Example Account" }; _accountId = _serviceProxy.Create(newAccount); Console.WriteLine("Created {0}", newAccount.Name); // Create a new opportunity Opportunity newOpportunity = new Opportunity { Name = "Example Opportunity", CustomerId = new EntityReference(Account.EntityLogicalName, _accountId), PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), FreightAmount = new Money(10.00m) }; _opportunityId = _serviceProxy.Create(newOpportunity); Console.WriteLine("Created {0}", newOpportunity.Name); // Create an opportunity product OpportunityProduct newOpportunityProduct1 = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Quantity = 3, Tax = new Money(4.80m) }; _opportunityProduct1Id = _serviceProxy.Create(newOpportunityProduct1); Console.WriteLine("Created opportunity product for {0} and {1}", newOpportunity.Name, newProduct1.Name); // Create a catalog product and override the price per unit OpportunityProduct newOpportunityProduct2 = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Quantity = 1, IsPriceOverridden = true, PricePerUnit = new Money(12), Tax = new Money(0.96m) }; _opportunityProduct2Id = _serviceProxy.Create(newOpportunityProduct2); Console.WriteLine("Created opportunity product for {0} and {1}", newOpportunity.Name, newProduct2.Name); // Create a write-in product with a manual discount OpportunityProduct newWriteInProduct = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityId), // set this attribute to make it a write-in product IsProductOverridden = true, ProductDescription = "Example Write-in Product", PricePerUnit = new Money(20.00m), Quantity = 5, ManualDiscountAmount = new Money(10.50m), Tax = new Money(7.16m) }; _writeInProductId = _serviceProxy.Create(newWriteInProduct); Console.WriteLine("Created {0}", newWriteInProduct.ProductDescription); return; }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { // Create a unit group. UoMSchedule unitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _service.Create(unitGroup); // Retrieve the unit. QueryExpression unitQuery = new QueryExpression() { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = { Conditions = { new ConditionExpression("uomscheduleid", ConditionOperator.Equal, _unitGroupId) } }, PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; UoM unit = (UoM)_service.RetrieveMultiple(unitQuery).Entities[0]; // Create an account. Account account = new Account { Name = "Litware, Inc.", Address1_StateOrProvince = "Colorado" }; _accountId = (_service.Create(account)); // Create the 2 contacts. Contact contact = new Contact() { FirstName = "Ben", LastName = "Andrews", EMailAddress1 = "*****@*****.**", Address1_City = "Redmond", Address1_StateOrProvince = "WA", Address1_Telephone1 = "(206)555-5555", ParentCustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName } }; _contactIdList.Add(_service.Create(contact)); contact = new Contact() { FirstName = "Colin", LastName = "Wilcox", EMailAddress1 = "*****@*****.**", Address1_City = "Bellevue", Address1_StateOrProvince = "WA", Address1_Telephone1 = "(425)555-5555", ParentCustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName } }; _contactIdList.Add(_service.Create(contact)); // Create pricing and product objects. PriceLevel priceLevel = new PriceLevel() { Name = "Faux Price List" }; _priceLevelId = _service.Create(priceLevel); Product product = new Product() { ProductNumber = "1", QuantityDecimal = 4, Name = "Faux Product", Price = new Money(20.0M), DefaultUoMId = new EntityReference { Id = unit.Id, LogicalName = UoM.EntityLogicalName }, DefaultUoMScheduleId = new EntityReference { Id = _unitGroupId, LogicalName = UoMSchedule.EntityLogicalName } }; _productId = _service.Create(product); ProductPriceLevel productPrice = new ProductPriceLevel() { PriceLevelId = new EntityReference() { Id = _priceLevelId, LogicalName = PriceLevel.EntityLogicalName }, ProductId = new EntityReference() { Id = _productId, LogicalName = Product.EntityLogicalName }, UoMId = new EntityReference { Id = unit.Id, LogicalName = UoM.EntityLogicalName }, Amount = new Money(20.0M), }; _productPriceId = _service.Create(productPrice); // Create 3 orders. SalesOrder order = new SalesOrder() { Name = "Faux Order", DateFulfilled = new DateTime(2010, 8, 1), PriceLevelId = new EntityReference { Id = _priceLevelId, LogicalName = PriceLevel.EntityLogicalName }, CustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName }, FreightAmount = new Money(20.0M) }; _orderIdList.Add(_service.Create(order)); order = new SalesOrder() { Name = "Old Faux Order", DateFulfilled = new DateTime(2010, 4, 1), PriceLevelId = new EntityReference { Id = _priceLevelId, LogicalName = PriceLevel.EntityLogicalName }, CustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName }, FreightAmount = new Money(20.0M) }; _orderIdList.Add(_service.Create(order)); order = new SalesOrder() { Name = "Oldest Faux Order", DateFulfilled = new DateTime(2008, 8, 1), PriceLevelId = new EntityReference { Id = _priceLevelId, LogicalName = PriceLevel.EntityLogicalName }, CustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName }, FreightAmount = new Money(20.0M) }; _orderIdList.Add(_service.Create(order)); // Create 2 opportunities. Opportunity opportunity = new Opportunity() { Name = "Litware, Inc. Opportunity 1", EstimatedCloseDate = new DateTime(2011, 1, 1), CustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName } }; _opportunityIdList.Add(_service.Create(opportunity)); opportunity = new Opportunity() { Name = "Litware, Inc. Opportunity 2", EstimatedCloseDate = new DateTime(2020, 1, 1), CustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName } }; _opportunityIdList.Add(_service.Create(opportunity)); }
/// <summary> /// This method creates any entity records that this sample requires. /// Create a unit group and price list. /// </summary> public void CreateRequiredRecords() { Console.WriteLine("Creating required records for the sample:"); // Create a unit group. UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); Console.WriteLine("Created {0}", newUnitGroup.Name); // retrieve the unit id. QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression(), PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; unitQuery.Criteria.AddCondition("uomscheduleid", ConditionOperator.Equal, _unitGroupId); // Retrieve the unit. UoM unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; Console.WriteLine("Retrieved {0}", unit.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); Console.WriteLine("Created {0}", newPriceList.Name); // Create a product record to be cloned. Product newProduct = new Product { Name = "Example Product", ProductNumber = "P001", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, unit.Id) }; _productId = _serviceProxy.Create(newProduct); Console.WriteLine("\nCreated {0}", newProduct.Name); // Create a price list item for the product ProductPriceLevel newPriceListItem = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _productId), UoMId = new EntityReference(UoM.EntityLogicalName, unit.Id), Amount = new Money(20) }; _priceListItemId = _serviceProxy.Create(newPriceListItem); Console.WriteLine("Created price list for {0}", newProduct.Name); return; }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { #region Create or Retrieve the necessary system users // Retrieve the ldapPath String ldapPath = String.Empty; // Retrieve the sales team - 1 sales manager and 2 sales representatives. _salesManagerId = SystemUserProvider.RetrieveSalesManager(_serviceProxy, ref ldapPath); _salesRepresentativeIds = SystemUserProvider.RetrieveSalespersons(_serviceProxy, ref ldapPath); #endregion #region Create records to support Opportunity records // Create a unit group UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); // Retrieve the default unit id that was automatically created // when we created the Unit Group QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "uomscheduleid", Operator = ConditionOperator.Equal, Values = { _unitGroupId } } } }, PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; // Retrieve the unit. UoM unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; _defaultUnitId = unit.UoMId.Value; // Create a few products Product newProduct1 = new Product { ProductNumber = "1", Name = "Example Product 1", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _product1Id = _serviceProxy.Create(newProduct1); Console.WriteLine("Created {0}", newProduct1.Name); Product newProduct2 = new Product { ProductNumber = "2", Name = "Example Product 2", ProductStructure = new OptionSetValue(1), QuantityDecimal = 3, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _product2Id = _serviceProxy.Create(newProduct2); Console.WriteLine("Created {0}", newProduct2.Name); // Create a new discount list DiscountType newDiscountType = new DiscountType { Name = "Example Discount List", IsAmountType = false }; _discountTypeId = _serviceProxy.Create(newDiscountType); // Create a new discount Discount newDiscount = new Discount { DiscountTypeId = new EntityReference(DiscountType.EntityLogicalName, _discountTypeId), LowQuantity = 5, HighQuantity = 10, Percentage = 3 }; _discountId = _serviceProxy.Create(newDiscount); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); // Create a price list item for the first product and apply volume discount ProductPriceLevel newPriceListItem1 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(20), DiscountTypeId = new EntityReference(DiscountType.EntityLogicalName, _discountTypeId) }; _priceListItem1Id = _serviceProxy.Create(newPriceListItem1); // Create a price list item for the second product ProductPriceLevel newPriceListItem2 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(15) }; _priceListItem2Id = _serviceProxy.Create(newPriceListItem2); // Publish Product 1 SetStateRequest publishRequest1 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product1Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest1); // Publish Product 2 SetStateRequest publishRequest2 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product2Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest2); Console.WriteLine("Published {0} and {1}", newProduct1.Name, newProduct2.Name); // Create an account record for the opportunity's potential customerid Account newAccount = new Account { Name = "Litware, Inc.", Address1_PostalCode = "60661" }; _accountIds.Add(_serviceProxy.Create(newAccount)); newAccount = new Account { Name = "Margie's Travel", Address1_PostalCode = "99999" }; _accountIds.Add(_serviceProxy.Create(newAccount)); #endregion Create records to support Opportunity records #region Create Opportunity records // Create a new opportunity with user specified estimated revenue Opportunity newOpportunity = new Opportunity { Name = "Example Opportunity", CustomerId = new EntityReference(Account.EntityLogicalName, _accountIds[0]), PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), IsRevenueSystemCalculated = false, EstimatedValue = new Money(400.00m), FreightAmount = new Money(10.00m), DiscountAmount = new Money(0.10m), DiscountPercentage = 0.20m, ActualValue = new Money(400.00m), OwnerId = new EntityReference { Id = _salesRepresentativeIds[0], LogicalName = SystemUser.EntityLogicalName } }; _opportunityIds.Add(_serviceProxy.Create(newOpportunity)); Opportunity secondOpportunity = new Opportunity { Name = "Example Opportunity 2", CustomerId = new EntityReference(Account.EntityLogicalName, _accountIds[1]), PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), IsRevenueSystemCalculated = false, EstimatedValue = new Money(400.00m), FreightAmount = new Money(10.00m), DiscountAmount = new Money(0.10m), DiscountPercentage = 0.20m, ActualValue = new Money(400.00m), OwnerId = new EntityReference { Id = _salesRepresentativeIds[1], LogicalName = SystemUser.EntityLogicalName } }; _opportunityIds.Add(_serviceProxy.Create(secondOpportunity)); // Create a catalog product OpportunityProduct catalogProduct = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityIds[0]), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Quantity = 8, Tax = new Money(12.42m), }; _catalogProductId = _serviceProxy.Create(catalogProduct); // Create another catalog product and override the list price OpportunityProduct catalogProductPriceOverride = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityIds[1]), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Quantity = 3, Tax = new Money(2.88m), IsPriceOverridden = true, PricePerUnit = new Money(12) }; _catalogProductPriceOverrideId = _serviceProxy.Create( catalogProductPriceOverride); // create a new write-in opportunity product with a manual discount applied OpportunityProduct writeInProduct = new OpportunityProduct { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, _opportunityIds[1]), IsProductOverridden = true, ProductDescription = "Example Write-in Product", PricePerUnit = new Money(20.00m), Quantity = 5, ManualDiscountAmount = new Money(10.50m), Tax = new Money(7.16m) }; _writeInProductId = _serviceProxy.Create(writeInProduct); // Close the opportunities as 'Won' WinOpportunityRequest winRequest = new WinOpportunityRequest() { OpportunityClose = new OpportunityClose() { OpportunityId = new EntityReference { Id = _opportunityIds[0], LogicalName = Opportunity.EntityLogicalName }, ActualRevenue = new Money(400.00M), ActualEnd = DateTime.Today }, Status = new OptionSetValue(3) }; _serviceProxy.Execute(winRequest); winRequest = new WinOpportunityRequest() { OpportunityClose = new OpportunityClose() { OpportunityId = new EntityReference { Id = _opportunityIds[1], LogicalName = Opportunity.EntityLogicalName }, ActualRevenue = new Money(400.00M), ActualEnd = DateTime.Today }, Status = new OptionSetValue(3) }; _serviceProxy.Execute(winRequest); #endregion Create Opportunity records }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { // Create a unit group. UoMSchedule unitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _service.Create(unitGroup); // Retrieve the unit. QueryExpression unitQuery = new QueryExpression() { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = { Conditions = { new ConditionExpression ("uomscheduleid", ConditionOperator.Equal, _unitGroupId) } }, PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; UoM unit = (UoM)_service.RetrieveMultiple(unitQuery).Entities[0]; // Create an account. Account account = new Account { Name = "Litware, Inc.", Address1_StateOrProvince = "Colorado" }; _accountId = (_service.Create(account)); // Create the 2 contacts. Contact contact = new Contact() { FirstName = "Ben", LastName = "Andrews", EMailAddress1 = "*****@*****.**", Address1_City = "Redmond", Address1_StateOrProvince = "WA", Address1_Telephone1 = "(206)555-5555", ParentCustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName } }; _contactIdList.Add(_service.Create(contact)); contact = new Contact() { FirstName = "Colin", LastName = "Wilcox", EMailAddress1 = "*****@*****.**", Address1_City = "Bellevue", Address1_StateOrProvince = "WA", Address1_Telephone1 = "(425)555-5555", ParentCustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName } }; _contactIdList.Add(_service.Create(contact)); // Create pricing and product objects. PriceLevel priceLevel = new PriceLevel() { Name = "Faux Price List" }; _priceLevelId = _service.Create(priceLevel); Product product = new Product() { ProductNumber = "1", QuantityDecimal = 4, Name = "Faux Product", Price = new Money(20.0M), DefaultUoMId = new EntityReference { Id = unit.Id, LogicalName = UoM.EntityLogicalName }, DefaultUoMScheduleId = new EntityReference { Id = _unitGroupId, LogicalName = UoMSchedule.EntityLogicalName } }; _productId = _service.Create(product); ProductPriceLevel productPrice = new ProductPriceLevel() { PriceLevelId = new EntityReference() { Id = _priceLevelId, LogicalName = PriceLevel.EntityLogicalName }, ProductId = new EntityReference() { Id = _productId, LogicalName = Product.EntityLogicalName }, UoMId = new EntityReference { Id = unit.Id, LogicalName = UoM.EntityLogicalName }, Amount = new Money(20.0M), }; _productPriceId = _service.Create(productPrice); // Create 3 orders. SalesOrder order = new SalesOrder() { Name = "Faux Order", DateFulfilled = new DateTime(2010, 8, 1), PriceLevelId = new EntityReference { Id = _priceLevelId, LogicalName = PriceLevel.EntityLogicalName }, CustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName }, FreightAmount = new Money(20.0M) }; _orderIdList.Add(_service.Create(order)); order = new SalesOrder() { Name = "Old Faux Order", DateFulfilled = new DateTime(2010, 4, 1), PriceLevelId = new EntityReference { Id = _priceLevelId, LogicalName = PriceLevel.EntityLogicalName }, CustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName }, FreightAmount = new Money(20.0M) }; _orderIdList.Add(_service.Create(order)); order = new SalesOrder() { Name = "Oldest Faux Order", DateFulfilled = new DateTime(2008, 8, 1), PriceLevelId = new EntityReference { Id = _priceLevelId, LogicalName = PriceLevel.EntityLogicalName }, CustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName }, FreightAmount = new Money(20.0M) }; _orderIdList.Add(_service.Create(order)); // Create 2 opportunities. Opportunity opportunity = new Opportunity() { Name = "Litware, Inc. Opportunity 1", EstimatedCloseDate = new DateTime(2011, 1, 1), CustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName } }; _opportunityIdList.Add(_service.Create(opportunity)); opportunity = new Opportunity() { Name = "Litware, Inc. Opportunity 2", EstimatedCloseDate = new DateTime(2020, 1, 1), CustomerId = new EntityReference { Id = _accountId, LogicalName = account.LogicalName } }; _opportunityIdList.Add(_service.Create(opportunity)); }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { // Create a unit group UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); Console.WriteLine("Create {0}", newUnitGroup.Name); // Retrieve the default unit id that was automatically created // when we created the Unit Group QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "uomscheduleid", Operator = ConditionOperator.Equal, Values = { _unitGroupId } } } }, PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; // Retrieve the unit. UoM unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; _defaultUnitId = unit.UoMId.Value; // Create a few products Product newProduct = new Product { ProductNumber = "1", Name = "Example Product", ProductStructure = new OptionSetValue(1), QuantityDecimal = 1, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _productId = _serviceProxy.Create(newProduct); newProduct.Id = _productId; Console.WriteLine("Create {0}", newProduct.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); // Create a price list item for the product and apply volume discount ProductPriceLevel newPriceListItem = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _productId), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(20.0M), }; _priceListItemId = _serviceProxy.Create(newPriceListItem); // Publish the product SetStateRequest publishRequest = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _productId), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest); Console.WriteLine("Published {0}", newProduct.Name); // Create an account record for the opportunity's potential customerid Account newAccount = new Account { Name = "Litware, Inc.", Address1_PostalCode = "60661" }; _accountId = _serviceProxy.Create(newAccount); newAccount.Id = _accountId; }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { #region Create or Retrieve the necessary system users // Retrieve the ldapPath String ldapPath = String.Empty; // Retrieve the sales team - 1 sales manager and 2 sales representatives. _salesManagerId = SystemUserProvider.RetrieveSalesManager(_serviceProxy, ref ldapPath); _salesRepresentativeIds = SystemUserProvider.RetrieveSalespersons(_serviceProxy, ref ldapPath); #endregion #region Create records to support Opportunity records // Create a unit group UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); // Retrieve the default unit id that was automatically created // when we created the Unit Group QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "uomscheduleid", Operator = ConditionOperator.Equal, Values = { _unitGroupId } } } }, PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; // Retrieve the unit. UoM unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; _defaultUnitId = unit.UoMId.Value; // Create a few products Product newProduct1 = new Product { ProductNumber = "1", Name = "Example Product 1", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _product1Id = _serviceProxy.Create(newProduct1); Console.WriteLine("Created {0}", newProduct1.Name); Product newProduct2 = new Product { ProductNumber = "2", Name = "Example Product 2", ProductStructure = new OptionSetValue(1), QuantityDecimal = 3, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _product2Id = _serviceProxy.Create(newProduct2); Console.WriteLine("Created {0}", newProduct2.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); // Create a price list item for the first product and apply volume discount ProductPriceLevel newPriceListItem1 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(20) }; _priceListItem1Id = _serviceProxy.Create(newPriceListItem1); // Create a price list item for the second product ProductPriceLevel newPriceListItem2 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(15) }; _priceListItem2Id = _serviceProxy.Create(newPriceListItem2); //Publish Product1 SetStateRequest publishRequest1 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product1Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest1); //Publish Product2 SetStateRequest publishRequest2 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product2Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest2); Console.WriteLine("Published both the products"); // Create an account record for the opportunity's potential customerid Account newAccount = new Account { Name = "Margie's Travel", Address1_PostalCode = "99999" }; _accountId = (_serviceProxy.Create(newAccount)); #endregion Create records to support Opportunity records }
/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { #region Create or Retrieve the necessary system users // Retrieve the ldapPath String ldapPath = String.Empty; // Retrieve the sales team - 1 sales manager and 2 sales representatives. _salesManagerId = SystemUserProvider.RetrieveSalesManager(_serviceProxy, ref ldapPath); _salesRepresentativeIds = SystemUserProvider.RetrieveSalespersons(_serviceProxy, ref ldapPath); #endregion #region Create records to support Opportunity records // Create a unit group UoMSchedule newUnitGroup = new UoMSchedule { Name = "Example Unit Group", BaseUoMName = "Example Primary Unit" }; _unitGroupId = _serviceProxy.Create(newUnitGroup); // Retrieve the default unit id that was automatically created // when we created the Unit Group QueryExpression unitQuery = new QueryExpression { EntityName = UoM.EntityLogicalName, ColumnSet = new ColumnSet("uomid", "name"), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "uomscheduleid", Operator = ConditionOperator.Equal, Values = { _unitGroupId } } } }, PageInfo = new PagingInfo { PageNumber = 1, Count = 1 } }; // Retrieve the unit. UoM unit = (UoM)_serviceProxy.RetrieveMultiple(unitQuery).Entities[0]; _defaultUnitId = unit.UoMId.Value; // Create a few products Product newProduct1 = new Product { ProductNumber = "1", Name = "Example Product 1", ProductStructure = new OptionSetValue(1), QuantityDecimal = 2, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _product1Id = _serviceProxy.Create(newProduct1); Console.WriteLine("Created {0}", newProduct1.Name); Product newProduct2 = new Product { ProductNumber = "2", Name = "Example Product 2", ProductStructure = new OptionSetValue(1), QuantityDecimal = 3, DefaultUoMScheduleId = new EntityReference(UoMSchedule.EntityLogicalName, _unitGroupId), DefaultUoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId) }; _product2Id = _serviceProxy.Create(newProduct2); Console.WriteLine("Created {0}", newProduct2.Name); // Create a price list PriceLevel newPriceList = new PriceLevel { Name = "Example Price List" }; _priceListId = _serviceProxy.Create(newPriceList); // Create a price list item for the first product and apply volume discount ProductPriceLevel newPriceListItem1 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product1Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(20) }; _priceListItem1Id = _serviceProxy.Create(newPriceListItem1); // Create a price list item for the second product ProductPriceLevel newPriceListItem2 = new ProductPriceLevel { PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, _priceListId), ProductId = new EntityReference(Product.EntityLogicalName, _product2Id), UoMId = new EntityReference(UoM.EntityLogicalName, _defaultUnitId), Amount = new Money(15) }; _priceListItem2Id = _serviceProxy.Create(newPriceListItem2); //Publish Product1 SetStateRequest publishRequest1 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product1Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest1); //Publish Product2 SetStateRequest publishRequest2 = new SetStateRequest { EntityMoniker = new EntityReference(Product.EntityLogicalName, _product2Id), State = new OptionSetValue((int)ProductState.Active), Status = new OptionSetValue(1) }; _serviceProxy.Execute(publishRequest2); Console.WriteLine("Published both the products"); // Create an account record for the opportunity's potential customerid Account newAccount = new Account { Name = "Margie's Travel", Address1_PostalCode = "99999" }; _accountId = (_serviceProxy.Create(newAccount)); #endregion Create records to support Opportunity records }