All types of products are created by using the EcoResProductService service. However, the methods to create a distinct product, a product master, and a product variant are different so each method is described separately.<\/p>\n
To create a distinct product, use the EcoResProductService.create operation. First, create a product using C# code, and then create an XML document with data to create a product.<\/p>\n
\n
static<\/span> void<\/span> createDistinctProduct()
{
AxdEntity_Product_EcoResDistinctProduct distinctProduct = new<\/span> AxdEntity_Product_EcoResDistinctProduct()
{
DisplayProductNumber = \"Bulb60W\"<\/span>,
ProductType = AxdEnum_EcoResProductType.Item,
SearchName = \"Bulb60W\"<\/span>
};
distinctProduct.Translation = new<\/span> AxdEntity_Translation[1];
distinctProduct.Translation[0] = new<\/span> AxdEntity_Translation()
{
LanguageId = \"en-us\"<\/span>, Name = \"Transparent Bulb 60W\"<\/span>
};
distinctProduct.Identifier = new<\/span> AxdEntity_Identifier[1];
distinctProduct.Identifier[0] = new<\/span> AxdEntity_Identifier()
{
ProductNumber = \"Bulb60W\"<\/span>
};
distinctProduct.StorageDimGroup = new<\/span> AxdEntity_StorageDimGroup[1];
distinctProduct.StorageDimGroup[0] = new<\/span> AxdEntity_StorageDimGroup()
{
Product = \"Bulb60W\"<\/span>, StorageDimensionGroup = \"Std-Dim\"<\/span>
};
distinctProduct.TrackingDimGroup = new<\/span> AxdEntity_TrackingDimGroup[1];
distinctProduct.TrackingDimGroup[0] = new<\/span> AxdEntity_TrackingDimGroup()
{
Product = \"Bulb60W\"<\/span>, TrackingDimensionGroup = \"Std-Dim\"<\/span>
};
AxdEcoResProduct axdProduct = new<\/span> AxdEcoResProduct()
{
Product = new<\/span> AxdEntity_Product_EcoResProduct[1] { distinctProduct }
};
CallContext ctx = new<\/span> CallContext();
EcoResProductServiceClient service = new<\/span> EcoResProductServiceClient();
try<\/span>
{
service.create(ctx, axdProduct);
}
catch<\/span> (Exception e)
{
System.Console.WriteLine(e.Message);
System.Console.ReadKey();
}
}<\/pre>\n<\/div>\nAs it appears, the create operation accepts an array of products so it is possible to create multiple products in one call to the service.<\/p>\n
The following XML code creates a distinct product. Note that storage and tracking dimension groups are specified. The storage and tracking dimension groups are not mandatory information to create a product so the C# code for the creation of a distinct product does not create these groups.<\/p>\n
\n
<?<\/span>xml<\/span> version<\/span>=\"1.0\"<\/span> encoding<\/span>=\"UTF-8\"<\/span>?><\/span>
<<\/span>Envelope<\/span> xmlns<\/span>=\"http:\/\/schemas.microsoft.com\/dynamics\/2011\/01\/documents\/Message\"<\/span>><\/span>
<<\/span>Header<\/span>><\/span>
<<\/span>Company<\/span>><\/span>DMO<\/<\/span>Company<\/span>><\/span>
<<\/span>Action<\/span>><\/span>http:\/\/schemas.microsoft.com\/dynamics\/2008\/01\/services\/EcoResProductService\/create<\/<\/span>Action<\/span>><\/span>
<\/<\/span>Header<\/span>><\/span>
<<\/span>Body<\/span>><\/span>
<<\/span>MessageParts<\/span> xmlns<\/span>=\"http:\/\/schemas.microsoft.com\/dynamics\/2011\/01\/documents\/Message\"<\/span>><\/span>
<<\/span>EcoResProduct<\/span> xmlns<\/span>=\"http:\/\/schemas.microsoft.com\/dynamics\/2008\/01\/documents\/EcoResProduct\"<\/span>><\/span>
<<\/span>Product<\/span> xmlns:xsi<\/span>=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"<\/span> class<\/span>=\"entity\"<\/span> xsi:type<\/span>=\"AxdEntity_Product_EcoResDistinctProduct\"<\/span>><\/span>
<<\/span>DisplayProductNumber<\/span>><\/span>Bulb40W<\/<\/span>DisplayProductNumber<\/span>><\/span>
<<\/span>SearchName<\/span>><\/span>Bulb40W<\/<\/span>SearchName<\/span>><\/span>
<<\/span>ProductType<\/span>><\/span>Item<\/<\/span>ProductType<\/span>><\/span>
<<\/span>Translation<\/span> class<\/span>=\"entity\"<\/span>><\/span>
<<\/span>LanguageId<\/span>><\/span>en-us<\/<\/span>LanguageId<\/span>><\/span>
<<\/span>Name<\/span>><\/span>Transparent Bulb 40W<\/<\/span>Name<\/span>><\/span>
<\/<\/span>Translation<\/span>><\/span>
<<\/span>StorageDimGroup<\/span> class<\/span>=\"entity\"<\/span>><\/span>
<<\/span>Product<\/span>><\/span>Bulb40W<\/<\/span>Product<\/span>><\/span>
<<\/span>StorageDimensionGroup<\/span>><\/span>Std-Dim<\/<\/span>StorageDimensionGroup<\/span>><\/span>
<\/<\/span>StorageDimGroup<\/span>><\/span>
<<\/span>TrackingDimGroup<\/span> class<\/span>=\"entity\"<\/span>><\/span>
<<\/span>Product<\/span>><\/span>Bulb40W<\/<\/span>Product<\/span>><\/span>
<<\/span>TrackingDimensionGroup<\/span>><\/span>Std-Dim<\/<\/span>TrackingDimensionGroup<\/span>><\/span>
<\/<\/span>TrackingDimGroup<\/span>><\/span>
<<\/span>Identifier<\/span> class<\/span>=\"entity\"<\/span>><\/span>
<<\/span>ProductNumber<\/span>><\/span>Bulb40W<\/<\/span>ProductNumber<\/span>><\/span>
<\/<\/span>Identifier<\/span>><\/span>
<\/<\/span>Product<\/span>><\/span>
<\/<\/span>EcoResProduct<\/span>><\/span>
<\/<\/span>MessageParts<\/span>><\/span>
<\/<\/span>Body<\/span>><\/span>
<\/<\/span>Envelope<\/span>><\/span><\/pre>\n<\/div>\nThe EcoResProduct element can contain multiple Product elements in order to create multiple products in one service call.<\/p>\n
Create a product master and a related product variant<\/h4>\n
To create a product master, use the EcoResProductService.create operation. Then use the EcoResProductMasterDimValue.create operation to associate product dimension values with the product master. Finally, use the EcoResProductService.create operation again, this time to create a product variant.<\/p>\n
The code to create a product master is basically similar to the code that creates a distinct product. One difference is the code that associates the product master with a product dimension group (in the following example: Size-Dim):<\/p>\n
\n
static<\/span> void<\/span> createMaster()
{
\/\/master definition<\/span>
AxdEntity_Product_EcoResProductMaster productMaster = new<\/span> AxdEntity_Product_EcoResProductMaster()
{
DisplayProductNumber = \"RunningShoe\"<\/span>,
ProductType = AxdEnum_EcoResProductType.Item,
SearchName = \"RunningShoe\"<\/span>,
};
productMaster.Translation = new<\/span> AxdEntity_Translation[1];
productMaster.Translation[0] = new<\/span> AxdEntity_Translation()
{
LanguageId = \"en-us\"<\/span>, Name = \"Comfortable running shoe\"<\/span>
};
productMaster.Identifier = new<\/span> AxdEntity_Identifier[1];
productMaster.Identifier[0] = new<\/span> AxdEntity_Identifier()
{
ProductNumber = \"RunningShoe\"<\/span>
};
productMaster.ProductDimGroup = new<\/span> AxdEntity_ProductDimGroup[1];
productMaster.ProductDimGroup[0] = new<\/span> AxdEntity_ProductDimGroup()
{
Product = \"RunningShoe\"<\/span>, ProductDimensionGroup = \"Size-Dim\"<\/span>
};
productMaster.VariantConfigurationTechnology = AxdEnum_EcoResVariantConfigurationTechnologyType.PredefinedVariants;
AxdEcoResProduct axdProduct = new<\/span> AxdEcoResProduct()
{
Product = new<\/span> AxdEntity_Product_EcoResProduct[1] { productMaster }
};
CallContext ctx = new<\/span> CallContext();
EcoResProductServiceClient productService = new<\/span> EcoResProductServiceClient();
try<\/span>
{
productService.create(ctx, axdProduct);
}
catch<\/span> (Exception e)
{
System.Console.WriteLine(e.Message);
System.Console.ReadKey();
}
}<\/pre>\n<\/div>\nWhen the product master is created, associate two size dimension values with the product master (size L and M):<\/p>\n
\n
static<\/span> void<\/span> createMasterDimensions()
{
\/\/master dimensions definition (two sizes, L and M)<\/span>
AxdEntity_MasterDim_EcoResProductMasterSize sizeDimensionL = new<\/span> AxdEntity_MasterDim_EcoResProductMasterSize()
{
SizeProductMaster = \"RunningShoe\"<\/span>,
Size = \"L\"<\/span>,
EcoResSize = new<\/span> AxdEntity_EcoResSize[1]
{
new<\/span> AxdEntity_EcoResSize() { Name = \"L\"<\/span> }
}
};
AxdEntity_MasterDim_EcoResProductMasterSize sizeDimensionM = new<\/span> AxdEntity_MasterDim_EcoResProductMasterSize()
{
SizeProductMaster = \"RunningShoe\"<\/span>,
Size = \"M\"<\/span>,
EcoResSize = new<\/span> AxdEntity_EcoResSize[1]
{
new<\/span> AxdEntity_EcoResSize() { Name = \"M\"<\/span> }
}
};
AxdEcoResProductMasterDimValue axdDimValue = new<\/span> AxdEcoResProductMasterDimValue()
{
MasterDim = new<\/span> AxdEntity_MasterDim_EcoResProductMasterDimensionValue[2] { sizeDimensionL, sizeDimensionM }