How To Retrieve An Attribute Field In StockItems I

2019-09-04 05:16发布

问题:

I am wondering if a specific attribute can be retrieved in the Web Service API? I have tried IN202500.AttributesAttributes.Value when exporting but that listed all attributes of the inventory. I also noticed the attributes are saved in the table as [AttributeName]_Attributes in the Inventory table, is there any way of retrieving this?

This is the code I am using (expecting it would retrieve the Attributes)

IN202500Content IN202500 = context.IN202500GetSchema();
context.IN202500Clear();

Command[] oCmd = new Command[] {
                      IN202500.StockItemSummary.ServiceCommands.EveryInventoryID,
                      IN202500.StockItemSummary.InventoryID,
                      IN202500.StockItemSummary.Description, 
                      IN202500.StockItemSummary.ItemStatus, 
                      IN202500.GeneralSettingsItemDefaults.ItemClass, 
                      IN202500.GeneralSettingsItemDefaults.LotSerialClass,
                      new Field  {  
                          ObjectName = IN202500.StockItemSummary.InventoryID.ObjectName,
                          FieldName = "BARCODE_Attributes"}, 
                      new Field  {  
                          ObjectName = IN202500.StockItemSummary.InventoryID.ObjectName, 
                          FieldName = "DfltReceiptLocationID"},   
                      new Field  {  
                          ObjectName = IN202500.StockItemSummary.InventoryID.ObjectName, 
                          FieldName = "LastModifiedDateTime"}   
                      };

Filter[] oFilter = new Filter[] {
                      new Filter 
                      {
                          Field = new Field {
                              ObjectName = IN202500.StockItemSummary.InventoryID.ObjectName,
                              FieldName = "LastModifiedDateTime"},
                          Condition = FilterCondition.Greater,
                          Value = SyncDate
                       }
                    };

String[][] sReturn = context.IN202500Export(oCmd, oFilter, 0, true, false);

But the Attribute field returned is an empty string. Thanks, G

回答1:

You can leverage the dynamic fields that are added to the primary view of the screen to retrieve specific attribute values. These fields don't show up in the WSDL schema, so you have to create a Field object and pass it to the Export function.

I looked up the field name and object name from an Export scenario by displaying the Native Object / Native Field name columns. Resulting Export call looks like this:

        var result = screen.Export(new IN202500.Command[] { 
            new IN202500.Value() { LinkedCommand = schema.StockItemSummary.InventoryID, Value = "Z730P00073"},
            schema.StockItemSummary.InventoryID,
            schema.StockItemSummary.Description,
            new IN202500.Field { FieldName = "COLOR_Attributes", ObjectName = "Item"},
            new IN202500.Field { FieldName = "HWMAN_Attributes", ObjectName = "Item"},
        }, null, 0, true, true);

This code will retrieve the two attributes value (COLOR and HWMAN Attributes) for a specific inventory item (Z730P00073). The result variable contains a two-dimensional array, let me know if you need help getting results from the array.



回答2:

This example shows how to add an item and set attributes and image:

        byte[] filedata;
        using (System.IO.FileStream file = System.IO.File.Open(@"C:\1.jpg", System.IO.FileMode.Open))
        {
            filedata = new byte[file.Length];
            file.Read(filedata, 0, filedata.Length);
        }

        Random rnd = new Random();  
        string inventoryID = "CPU0000" + rnd.Next(100).ToString();
        context.IN202500Clear();            
        IN202500result = context.IN202500Submit(
            new Command[] 
            {
                IN202500.Actions.Insert,
                new Value { Value = inventoryID, LinkedCommand = IN202500.StockItemSummary.InventoryID },
                new Value { Value = inventoryID, LinkedCommand = IN202500.StockItemSummary.Description },
                new Value { Value = "CPU", LinkedCommand = IN202500.GeneralSettingsItemDefaults.ItemClass, Commit = true },
                new Value { Value = "TAXABLE", LinkedCommand = IN202500.GeneralSettingsItemDefaults.TaxCategory, Commit = true },                    
                //attributes - pairs 
                new Value { Value = "FREQUENCY", LinkedCommand = IN202500.AttributesAttributes.Attribute },
                new Value { Value = "1400", LinkedCommand = IN202500.AttributesAttributes.Value, Commit = true },
                new Value { Value = "CORE", LinkedCommand = IN202500.AttributesAttributes.Attribute },
                new Value { Value = "2 CORES", LinkedCommand = IN202500.AttributesAttributes.Value, Commit = true },
                new Value { Value = "INTGRAPH", LinkedCommand = IN202500.AttributesAttributes.Attribute },
                new Value { Value = "True", LinkedCommand = IN202500.AttributesAttributes.Value, Commit = true },
                //image
                new Value { Value = Convert.ToBase64String(filedata), FieldName = "1.jpg", LinkedCommand = IN202500.StockItemSummary.ServiceCommands.Attachment }, //uploads
                new Value { Value = "1.jpg", LinkedCommand = IN202500.Attributes.ImageUrl }, //sets as an item picture
                IN202500.Actions.Save,
                //return the result
                IN202500.StockItemSummary.InventoryID
        });


标签: acumatica