Microsoft Dynamics AX 2009 X++ Setting Attributes Issue

285 views
Skip to first unread message

dap...@gmail.com

unread,
Jul 17, 2013, 2:11:28 PM7/17/13
to ca...@googlegroups.com
Hi all,
 
Hopefully there are few others integrating DAX 5 to ChannelAdvisor that can look over my code. I'm having an issue with setting the attributes on a child SKU. No matter what I do, I can't get the API to update the color or size attributes. I don't get a error. I'm going to include the entire method, in case it might help someone else out.
 
Here is the code I have so far. Everything works except the attributes.
 
public static CA_InventoryService.APIResultOfArrayOfInventoryItemResponse SynchInventoryItems()
{
    CA_InventoryService.InventoryServiceSoapClient                  invSrv;
    CA_InventoryService.APICredentials                              cred;
    CA_InventoryService.PriceInfo                                   invPrice;
    CA_InventoryService.InventoryItemSubmit                         item;
    CA_InventoryService.APIResultOfArrayOfInventoryItemResponse     SyncResult;
    CA_InventoryService.APIResultOfArrayOfInventoryQuantityResponse SyncResult2;
    CA_InventoryService.InventoryItemQuantityAndPrice               QuantityPrice;
    CA_InventoryService.AttributeInfo                               attr;
    CA_InventoryService.AttributeInfo[]                             attrArray;
    CA_InventoryService.ImageInfoSubmit                             img;
    CA_InventoryService.ImageInfoSubmit[]                           imgArray;
    CA_InventoryService.DistributionCenterInfoSubmit                DistributionCenter;
    CA_InventoryService.DistributionCenterInfoSubmit[]              DistributionCenterArray;
    CA_InventoryService.VariationInfo                               VariationInfo;

    PriceDiscTable                  pdt;
    InventTable                     it;
    InventDimCombination            idc;
    InventDim                       id;
    InventSum                       ivs;
    InventItemBarcode               ibc;
    InventItemPrice                 iip;
    InventSize                      isize;
    InventColor                     icolor;
    System.Exception                ex;
    Cent_Environment                ce;
    Cent_TempItemDim                ci;
    Cent_TempItemWebDescription     cd;
    Cent_ChannelAdvisorParamTable   ca;
    str                             message;
    ;

    new InteropPermission(InteropKind::ClrInterop).assert();
    ce = new Cent_Environment();
    select ca;
    invSrv = new CA_InventoryService.InventoryServiceSoapClient("InventoryServiceSoap");
    imgArray  = new CA_InventoryService.ImageInfoSubmit[1]();
    DistributionCenterArray = new CA_InventoryService.DistributionCenterInfoSubmit[1]();
    cred  = new CA_InventoryService.APICredentials();
    cred.set_DeveloperKey(ca.DeveloperKey);
    cred.set_Password(ca.Password);

    while select it where it.ItemGroupId == 'PG' || it.ItemGroupId == 'FG'
    {

            cd = ce.getItemWebDescription(it.ItemId, "", "");
            if (cd)
            {
                try
                {
                    item = new CA_InventoryService.InventoryItemSubmit();
                    item.set_Sku(it.ItemId );
                    item.set_Title(cd.ShortDescription);
                    item.set_Subtitle(cd.ShortDescription);
                    item.set_ShortDescription(cd.ShortDescription);
                    item.set_Description(cd.ExtendedDescription);
                     //Begin Image Array
                    img = new CA_InventoryService.ImageInfoSubmit();
                    img.set_PlacementName('ITEMIMAGEURL1');
                    img.set_FilenameOrUrl(cd.Image);
                    imgArray.SetValue(img,0);
                    item.set_ImageList(imgArray);
                    //End Image Array

                   if (it.DimGroupId == "STW")
                    {

                        //Item-Color .. set parent color attributes
                        VariationInfo = new CA_InventoryService.VariationInfo();
                        VariationInfo.set_IsInRelationship(true);
                        VariationInfo.set_IsParent(true);
                        VariationInfo.set_RelationshipName("ItemColor");
                        VariationInfo.set_ParentSku(it.ItemId);
                        item.set_VariationInfo(VariationInfo);
                        //Create Parent Item
                        SyncResult = new CA_InventoryService.APIResultOfArrayOfInventoryItemResponse();
                        SyncResult = invSrv.SynchInventoryItem(cred,ca.AccountID,item);
                        //Begin child records
                        item = new CA_InventoryService.InventoryItemSubmit();
                        while select idc where idc.ItemId == it.ItemId
                        {
                            ci = ce.getItemDimByColorSize(idc.ItemId, idc.InventSizeId, idc.InventColorId);
                            cd = ce.getItemWebDescription(idc.ItemId, idc.InventSizeId, idc.InventColorId);
                            if (ci && cd)
                            {
                                select firstonly id where id.inventLocationID == "" && id.InventSiteId == "MWC" && id.InventSizeId == idc.InventSizeId && id.InventColorId == idc.InventColorId && id.configId == "";
                                select firstonly iip where iip.ItemId == it.ItemId && iip.InventDimId == id.inventDimId;
                                try
                                {
                                    select firstonly ivs where  ivs.ItemId == idc.ItemId && ivs.InventDimId == idc.inventDimId;
                                    select firstonly ibc where  ibc.ItemId == idc.ItemId && ibc.InventDimId == idc.inventDimId && ibc.barcodeSetupId == "UPC128";
                                    select firstonly isize where isize.ItemId == it.ItemId && isize.InventSizeId == id.InventSizeId;
                                    item = new CA_InventoryService.InventoryItemSubmit();
                                    VariationInfo = new CA_InventoryService.VariationInfo();
                                    VariationInfo.set_IsInRelationship(true);
                                    VariationInfo.set_IsParent(false);
                                    VariationInfo.set_RelationshipName("ItemColor");
                                    VariationInfo.set_ParentSku(it.ItemId);
                                    item.set_VariationInfo(VariationInfo);
                                    item.set_Title(cd.ShortDescription + " " + isize.Name + " " + icolor.Name);
                                    item.set_Sku(idc.ItemId + "-" + idc.InventSizeId + idc.InventColorId);
                                    item.set_Weight(new System.Decimal(ci.Weight));
                                    item.set_Height(new System.Decimal(ci.Height));
                                    item.set_Length(new System.Decimal(ci.Length));
                                    item.set_Width(new System.Decimal(ci.Width));
                                    item.set_UPC(ibc.itemBarCode);
                                    invPrice = new CA_InventoryService.PriceInfo();
                                    invPrice.set_RetailPrice(new System.Decimal(cd.Price));
                                    if (iip.PriceQty > 1)
                                    {
                                        invPrice.set_Cost(new System.Decimal(iip.Price/iip.PriceQty));
                                    }
                                    else
                                    {
                                        invPrice.set_Cost(new System.Decimal(iip.Price));
                                    }
                                    item.set_PriceInfo(invPrice);
 
 // This is were I'm trying to set the attributes.
                                    attrArray = new CA_InventoryService.AttributeInfo[1]();
                                    attr = new CA_InventoryService.AttributeInfo();
                                    attr.set_Name("Color");
                                    attr.set_Value(isize.Name);
                                    attrArray.SetValue(attr,0);
                                    item.set_AttributeList(attrArray);
//End attribute

                                    SyncResult = new CA_InventoryService.APIResultOfArrayOfInventoryItemResponse();
                                    SyncResult = invSrv.SynchInventoryItem(cred,ca.AccountID,item);
                                }
                                catch (Exception::CLRError)
                                {
                                    ex = CLRInterop::getLastException();
                                    info(ex.ToString());
                                    return SyncResult;
                                }
                                catch (Exception::CodeAccessSecurity)
                                {
                                    info("Code Access Security Error");
                                    return SyncResult;
                                }
                                catch (Exception::Internal)
                                {
                                    ex = CLRInterop::getLastException();
                                    if (ex)
                                    {
                                        info(ex.ToString());
                                    }
                                    else
                                    {
                                        info("Internal Error");
                                    }
                                    return SyncResult;
                                }
                                catch (Exception::Error)
                                {
                                    info("None of it worked (generic Exception)");
                                    return SyncResult;
                                }
                            }
                        }
                    }
                    else if (it.DimGroupId == "SCTW")
                    {
                        //Item-ColorSize .. set color and size attributes
                        VariationInfo = new CA_InventoryService.VariationInfo();
                        VariationInfo.set_IsInRelationship(true);
                        VariationInfo.set_IsParent(true);
                        VariationInfo.set_RelationshipName("ItemColorSize");
                        VariationInfo.set_ParentSku(it.ItemId);
                        item.set_VariationInfo(VariationInfo);
                        //Create Parent Item
                        SyncResult = new CA_InventoryService.APIResultOfArrayOfInventoryItemResponse();
                        SyncResult = invSrv.SynchInventoryItem(cred,ca.AccountID,item);
                        if (!SyncResult.get_Status())
                        {
                            message = SyncResult.get_Message();
                            info(message);
                        }
                        //Begin child records
                        item = new CA_InventoryService.InventoryItemSubmit();
                        while select idc where idc.ItemId == it.ItemId
                        {
                            ci = ce.getItemDimByColorSize(idc.ItemId, idc.InventSizeId, idc.InventColorId);
                            cd = ce.getItemWebDescription(idc.ItemId, idc.InventSizeId, idc.InventColorId);
                            if (ci && cd)
                            {
                                select firstonly id where id.inventLocationID == "" && id.InventSiteId == "MWC" && id.InventSizeId == idc.InventSizeId && id.InventColorId == idc.InventColorId && id.configId == "";
                                select firstonly iip where iip.ItemId == it.ItemId && iip.InventDimId == id.inventDimId;
                                try
                                {
                                    select firstonly ivs where  ivs.ItemId == idc.ItemId && ivs.InventDimId == idc.inventDimId;
                                    select firstonly ibc where  ibc.ItemId == idc.ItemId && ibc.InventDimId == idc.inventDimId && ibc.barcodeSetupId == "UPC128";
                                    select firstonly isize where isize.ItemId == it.ItemId && isize.InventSizeId == id.InventSizeId;
                                    select firstonly icolor where icolor.ItemId == it.ItemId && icolor.InventColorId == id.InventColorId;
                                    item = new CA_InventoryService.InventoryItemSubmit();
                                    VariationInfo = new CA_InventoryService.VariationInfo();
                                    VariationInfo.set_IsInRelationship(true);
                                    VariationInfo.set_IsParent(false);
                                    VariationInfo.set_RelationshipName("ItemColorSize");
                                    VariationInfo.set_ParentSku(it.ItemId);
                                    item.set_VariationInfo(VariationInfo);
                                    item.set_Title(cd.ShortDescription + " " + isize.Name + " " + icolor.Name);
                                    item.set_Sku(idc.ItemId + "-" + idc.InventSizeId + idc.InventColorId);
                                    item.set_Weight(new System.Decimal(ci.Weight));
                                    item.set_Height(new System.Decimal(ci.Height));
                                    item.set_Length(new System.Decimal(ci.Length));
                                    item.set_Width(new System.Decimal(ci.Width));
                                    item.set_UPC(ibc.itemBarCode);
                                    invPrice = new CA_InventoryService.PriceInfo();
                                    invPrice.set_RetailPrice(new System.Decimal(cd.Price));
                                    if (iip.PriceQty > 1)
                                    {
                                        invPrice.set_Cost(new System.Decimal(iip.Price/iip.PriceQty));
                                    }
                                    else
                                    {
                                        invPrice.set_Cost(new System.Decimal(iip.Price));
                                    }
                                    item.set_PriceInfo(invPrice);
 
 
// This is were I'm trying to set the attributes.
                                    attrArray = new CA_InventoryService.AttributeInfo[2]();
                                    attr = new CA_InventoryService.AttributeInfo();
                                    attr.set_Name("Color");
                                    attr.set_Value(isize.Name);
                                    attrArray.SetValue(attr,0);
                                    attr.set_Name("Size");
                                    attr.set_Value(icolor.Name);
                                    attrArray.SetValue(attr,1);
                                    item.set_AttributeList(attrArray);
//End attributes
 
 
                                    SyncResult = new CA_InventoryService.APIResultOfArrayOfInventoryItemResponse();
                                    SyncResult = invSrv.SynchInventoryItem(cred,ca.AccountID,item);
                                    if (!SyncResult.get_Status())
                                    {
                                        message = SyncResult.get_Message();
                                        info(message);
                                    }

                               }
                                catch (Exception::CLRError)
                                {
                                    ex = CLRInterop::getLastException();
                                    info(ex.ToString());
                                    return SyncResult;
                                }
                                catch (Exception::CodeAccessSecurity)
                                {
                                    info("Code Access Security Error");
                                    return SyncResult;
                                }
                                catch (Exception::Internal)
                                {
                                    ex = CLRInterop::getLastException();
                                    if (ex)
                                    {
                                        info(ex.ToString());
                                    }
                                    else
                                    {
                                        info("Internal Error");
                                    }
                                    return SyncResult;
                                }
                                catch (Exception::Error)
                                {
                                    info("None of it worked (generic Exception)");
                                    return SyncResult;
                                }
                            }
                        }
                     }
                    else
                    {
                        //Item level only .. no variation or attributes
                        //will need pricing, cost, dimensions, UPC
                        ci = ce.getItemDim(idc.ItemId, "AllBlank");
                        select firstonly ivs where  ivs.ItemId == idc.ItemId && ivs.InventDimId == "IDIM00004913";
                        select firstonly ibc where ibc.itemId == it.ItemId && ibc.inventDimId == "AllBlank" && ibc.barcodeSetupId == "UPC128" ;
                        select firstonly iip order by iip.ActivationDate desc where iip.ItemId == it.ItemId && iip.InventDimId ==  "00000021_081";
                        item.set_Weight(new System.Decimal(ci.Weight));
                        item.set_Height(new System.Decimal(ci.Height));
                        item.set_Length(new System.Decimal(ci.Length));
                        item.set_Width(new System.Decimal(ci.Width));
                        item.set_UPC(ibc.itemBarCode);
                        invPrice = new CA_InventoryService.PriceInfo();
                        invPrice.set_RetailPrice(new System.Decimal(cd.Price));
                        if (iip.PriceQty > 1)
                        {
                            invPrice.set_Cost(new System.Decimal(iip.Price/iip.PriceQty));
                        }
                        else
                        {
                            invPrice.set_Cost(new System.Decimal(iip.Price));
                        }
                        item.set_PriceInfo(invPrice);
                        DistributionCenter = new CA_InventoryService.DistributionCenterInfoSubmit();
                        DistributionCenter.set_Quantity(real2int(ivs.AvailPhysical));
                        DistributionCenter.set_DistributionCenterCode("Oklahoma City");
                        DistributionCenter.set_WarehouseLocation("CMAS-MWC");
                        DistributionCenterArray.SetValue(DistributionCenter,0);
                        item.set_DistributionCenterList(DistributionCenterArray);
                    }
                }
                catch (Exception::CLRError)
                {
                    ex = CLRInterop::getLastException();
                    info(ex.ToString());
                    return SyncResult;
                }
                catch (Exception::CodeAccessSecurity)
                {
                    info("Code Access Security Error");
                    return SyncResult;
                }
                catch (Exception::Internal)
                {
                    ex = CLRInterop::getLastException();
                    if (ex)
                    {
                        info(ex.ToString());
                    }
                    else
                    {
                        info("Internal Error");
                    }
                    return SyncResult;
                }
                catch (Exception::Error)
                {
                    info("None of it worked (generic Exception)");
                    return SyncResult;
                }
            }
    }
    CodeAccessPermission::revertAssert();
    return SyncResult;
}
 
 

[CA] Marshall McClure

unread,
Jul 18, 2013, 3:42:11 PM7/18/13
to ca...@googlegroups.com
Can you provide the XML produced by your code?  It is generally easier to diagnose a problem by looking at the XML rather than the code itself.  The XML is easier to read and allows me to try to reproduce the problem in a test account.

dap...@gmail.com

unread,
Jul 19, 2013, 11:45:55 AM7/19/13
to ca...@googlegroups.com
I do not have a way to capture the XML as the code integrates directly with CLR objects and then to the service.

[CA] Marshall McClure

unread,
Jul 19, 2013, 4:34:36 PM7/19/13
to ca...@googlegroups.com
There is a way to do it in .Net code: https://www.google.com/search?q=.net+soap+xml+logging.  You can also use Fiddler or any number of other tools to capture HTTP traffic.

Ashlesh Patel

unread,
Jan 16, 2015, 11:11:31 AM1/16/15
to ca...@googlegroups.com
Hi,

Today i am facing the same problem as you, but mine is while i am initializing the AttributeInfo[] i am getting below error:






Below is the error :

...

Ashlesh Patel

unread,
Jan 16, 2015, 11:13:06 AM1/16/15
to ca...@googlegroups.com
sorry to mention in my last post, i have to set the RunOn property of the Class to "Server" but if i will change it to "Client" the attributeInfo[] gets initialized successfully.
It would be a great help if you can comment on this, i know your post is too old but it is the only hope for me.

Thanks,
Ashlesh
...
Reply all
Reply to author
Forward
0 new messages