How to create an item using ( AIF ) ItemServices and EcoResProductServices in AX 2012

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.ServiceModel.Description;

using System.Text;

using Tutorial.AIF.CreateItem.EcoResProductServices;

using Tutorial.AIF.CreateItem.InventItemServices;

 

namespace Tutorial.AIF.CreateItem

{

class Program

{

static void Main(string[] args)

{

try

{

ItemServiceCreateRequest request = new ItemServiceCreateRequest();

ItemServiceClient client = new ItemServiceClient();

 

EcoResProductServiceCreateRequest prodRequest = new EcoResProductServiceCreateRequest();

EcoResProductServiceClient prodClient = new EcoResProductServiceClient();

 

ReqItemTableServiceCreateRequest reqItemRequest = new ReqItemTableServiceCreateRequest();

ReqItemTableServiceClient reqItemClient = new ReqItemTableServiceClient();

 

reqItemRequest.CallContext = new InventItemServices.CallContext();

reqItemRequest.CallContext.Company = "CAD";

reqItemRequest.CallContext.Language = "en-us";

reqItemRequest.CallContext.MessageId = Guid.NewGuid().ToString();

 

prodRequest.CallContext = new EcoResProductServices.CallContext();

prodRequest.CallContext.Language = "en-us";

prodRequest.CallContext.Company = "CAD";

prodRequest.CallContext.MessageId = Guid.NewGuid().ToString();

request.CallContext = new Tutorial.AIF.CreateItem.InventItemServices.CallContext();

request.CallContext.Language = "en-us";

request.CallContext.Company = "CAD";

request.CallContext.MessageId = Guid.NewGuid().ToString();

 

AxdEntity_Product_EcoResProduct[] ecoResProduct = new AxdEntity_Product_EcoResProduct[1];

ecoResProduct[0] = new AxdEntity_Product_EcoResDistinctProduct();

ecoResProduct[0].ProductType = AxdEnum_EcoResProductType.Item;

ecoResProduct[0].SearchName = "68727900121";

ecoResProduct[0].DisplayProductNumber = "ITEM002";

 

AxdEntity_Translation prodTranslation = new AxdEntity_Translation();

prodTranslation.Name = "ITEM002";

prodTranslation.LanguageId = "en-us";

 

ecoResProduct[0].Translation = new[] { prodTranslation };

 

 

AxdEntity_Identifier identifier = new AxdEntity_Identifier();

identifier.ProductNumber = "68727900121";

 

ecoResProduct[0].Identifier = new AxdEntity_Identifier[1];

ecoResProduct[0].Identifier[0] = identifier;

 

 

AxdEcoResProduct product = new AxdEcoResProduct();

product.Product = ecoResProduct;

 

prodClient.Open();

Tutorial.AIF.CreateItem.EcoResProductServices.EntityKey[] keys = prodClient.create(prodRequest.CallContext, product);

prodClient.Close();

 

AxdEntity_InventTable[] inventTable = new AxdEntity_InventTable[1];

inventTable[0] = new AxdEntity_InventTable();

inventTable[0].ItemId = "ITEM002";

inventTable[0].NameAlias = "ITEMNAMEALIAS";

inventTable[0].Product = "ITEM002";

//inventTable[0].Product = keys[0].KeyData[0].Value.Trim();

 

inventTable[0].StorageDimensionGroup = new[] { new AxdEntity_StorageDimensionGroup { StorageDimensionGroup = "DEF", ItemId = inventTable[0].ItemId } };

inventTable[0].TrackingDimensionGroup = new[] { new AxdEntity_TrackingDimensionGroup { TrackingDimensionGroup = "DEF", ItemId = inventTable[0].ItemId } };

inventTable[0].InventModelGroupItem = new[] { new AxdEntity_InventModelGroupItem { ModelGroupId = "DEF", ItemId = inventTable[0].ItemId } };

inventTable[0].InventItemGroupItem = new[] { new AxdEntity_InventItemGroupItem { ItemGroupId = "ALL", ItemId = inventTable[0].ItemId } };

 

//if you want to insert reqItemTable (item coverage settings) you need to create a service for that

//INVENTDIMID

inventTable[0].InventItemPurchSetup = new[] {

new AxdEntity_InventItemPurchSetup {

//HERE WE WILL ADD ORDER SPECIFIC SETTINGS FOR THIS PARTICULAR ITEM

ItemId = inventTable[0].ItemId,

InventDimPurchSetup = new AxdEntity_InventDimPurchSetup[] {

new AxdEntity_InventDimPurchSetup() {

InventDimId = "AllBlank"

}

},

DefaultInventDimPurchSetup = new [] {

new AxdEntity_DefaultInventDimPurchSetup() {

InventDimId = "AllBlank",

InventSiteId = "MTL-01"

}

}

},

//HERE WE WILL ADD SITE SPECIFIC SETTINGS FOR THIS PARTICULAR ITEM

new AxdEntity_InventItemPurchSetup {

ItemId = inventTable[0].ItemId,

InventDimPurchSetup = new AxdEntity_InventDimPurchSetup[] {

new AxdEntity_InventDimPurchSetup() {

InventSiteId = "MTL-01"

}

},

DefaultInventDimPurchSetup = new [] {

new AxdEntity_DefaultInventDimPurchSetup() {

InventLocationId = "01"

}

}

},

};

 

 

inventTable[0].InventItemSalesSetup = new[] {

new AxdEntity_InventItemSalesSetup {

ItemId = inventTable[0].ItemId,

InventDimSalesSetup = new AxdEntity_InventDimSalesSetup[] {

new AxdEntity_InventDimSalesSetup() {

InventDimId = "AllBlank"

}

},

DefaultInventDimSalesSetup = new [] {

new AxdEntity_DefaultInventDimSalesSetup() {

InventDimId = "AllBlank",

InventSiteId = "MTL-01"

}

}

 

},

new AxdEntity_InventItemSalesSetup {

ItemId = inventTable[0].ItemId,

InventDimSalesSetup = new AxdEntity_InventDimSalesSetup[] {

new AxdEntity_InventDimSalesSetup() {

InventSiteId = "MTL-01"

}

},

DefaultInventDimSalesSetup = new [] {

new AxdEntity_DefaultInventDimSalesSetup() {

InventLocationId = "01"

}

}

 

}

};

 

inventTable[0].InventItemInventSetup = new[] {

new AxdEntity_InventItemInventSetup {

ItemId = inventTable[0].ItemId,

InventDimInventSetup = new AxdEntity_InventDimInventSetup[] {

new AxdEntity_InventDimInventSetup() {

InventDimId = "AllBlank"

}

},

DefaultInventDimInventSetup = new [] {

new AxdEntity_DefaultInventDimInventSetup() {

InventDimId = "AllBlank",

InventSiteId = "MTL-01"

}

}

 

},

new AxdEntity_InventItemInventSetup {

ItemId = inventTable[0].ItemId,

InventDimInventSetup = new AxdEntity_InventDimInventSetup[] {

new AxdEntity_InventDimInventSetup() {

InventSiteId = "MTL-01"

}

},

DefaultInventDimInventSetup = new [] {

new AxdEntity_DefaultInventDimInventSetup() {

InventLocationId = "01"

}

}

 

}

};

 

 

AxdItem items = new AxdItem();

items.InventTable = inventTable;

 

client.Open();

client.create(request.CallContext, items);

client.Close();

}

catch (Exception e)

{

Console.WriteLine(e.Message);

Console.Read();

}

 

 

}

}

}

 

Imparted from here

No comments:

Post a Comment