Developer forum

Forum » Development » Add Orderlinefieldvalue code behind

Add Orderlinefieldvalue code behind

Martijn Bokhove
Reply

Hi

I'm trying to add a value to the orderline code behind.
The option is added in the CMS and I can see it in the EcomOrderlineFields table.

myOrderLine.OrderLineFieldValues.Count is 0, so I can't loop through the values and set the value.
When I try to add a value to one of the custom orderlinefield I get an error that says 'object not set to a reference'

The code I tried:
 Dim myOrderLineFV As eCommerce.Orders.OrderLineFieldValue = New eCommerce.Orders.OrderLineFieldValue("Fieldname""Value")
 myOrderLine.OrderLineFieldValues.Add(myOrderLineFV)
 myOrderLine.Save()
I also tried to create a new OrderLineFieldValueCollection and add it to the orderline, but that also creates the error 'object not set...'

How do I fill the custom OrderLineFieldValue correct?

Gr.
Martijn

Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Martijn

OrderLineFieldValues are not automatically added to the collection. It has to do with the product on the OrderLine. OrderLineFieldValues are associated with Groups and an OrderLineFieldValue is put into the collection if the product is in a Group with a relation to the OrderLineFieldValue.

That said, your code should work. You need to make sure, that an OrderLineField actually exists in the database with the systemname "Fieldname". If it doesn't then you need to create it.
As a sidenote, if you need to do multiple manipulations with the order, ie. add OrderLineFieldValues to more OrderLines or change some value on the order itself, you don't have to invoke the Save() method on each OrderLine after you've changed it. Simply do a Save() on the order when you're done. This will save all changes.

Be aware that by adding OrderLineFieldValues in this manner, you are effectively circumventing the relations set by eCom. It will still work but managing them in the Administation might be tricky.

Hope this helps :)

- Jeppe

 

You must be logged in to post in the forum