3

I can't find an example of this here or in the Acumatica sample code. Sending single attribute values works fine, but I can't find a way to send multi-select ones. They are returned as a comma-separated list in a string value, but sending them that way doesn't work. Also, sending them as multiple instances of single values doesn't work.

Here's what I've tried. (In the actual code I'm sending some other single attributes in the list, as well, but those work fine.)

// this results in nothing being set for the attribute
string interestedIn = "Brochure, Contact, Collecting small stones";
List<Acumatica.AttributeDetail> attributes = new List<Acumatica.AttributeDetail>();
attributes.Add(
    new Acumatica.AttributeDetail {
        Attribute = new Acumatica.StringValue { Value = "Interested in" },
        Value = new Acumatica.StringValue { Value = interestIn }
    }
);
custAdd.Attributes = attributes.ToArray();
// this results in the last item in the list being set for the attribute
string interestedIn = "Brochure, Contact, Collecting small stones";
List<Acumatica.AttributeDetail> attributes = new List<Acumatica.AttributeDetail>();
string[] interests = Convert.ToString(interestedIn).Split(',');
foreach (string interest in interests) {
    attributes.Add(
        new Acumatica.AttributeDetail {
            Attribute = new Acumatica.StringValue { Value = "Interested in" },
            Value = new Acumatica.StringValue { Value = interest.Trim() }
        }
    );
};
custAdd.Attributes = attributes.ToArray();
CSX321
  • 347
  • 2
  • 4

1 Answers1

1

From the source

MappedCustomer obj = bucket.Customer;
Core.API.Customer impl = obj.Local;
impl.Attributes = impl.Attributes ?? new List<AttributeValue>();
AttributeValue attribute = new AttributeValue();
attribute.AttributeID = new StringValue() { Value = attributeID };
attribute.ValueDescription = new StringValue() { Value = attributeValue?.ToString() };
impl.Attributes.Add(attribute);

Some subtle differences here. Also, I wonder if the .ToArray() call is necessary.

Patrick Chen
  • 1,028
  • 1
  • 6
  • 8
  • Is that the REST API? I forgot to mention that this project is using the SOAP API, although I did remember to tag the question that way. The ToArray() call was necessary because the SOAP Customer.Attributes member is an array of AttributeDetail objects. – CSX321 Aug 25 '21 at 22:07
  • This is from the ERP source code. I mention the ToArray Call because you're trying to append a payload item with a lot of commas in it. You should be able to just append the list without that call. – Patrick Chen Aug 26 '21 at 19:44
  • I'm not calling ToArray() for the comma-separated list. That is at a different level. The attribute list has other elements in it (not shown above). I have to call ToArray(), because Customer.Attributes is an array of AttributeDetails. I need to add an attribute in that array that itself has multiple values. Acumatica calls these multi-select attributes, I think. When retrieving the value of one of these attributes, it is returned as a comma-separated string, but sending it that way to try to update it doesn't work; it results in no value at all being set for the attribute. – CSX321 Aug 30 '21 at 14:20