cancel
Showing results for 
Search instead for 
Did you mean: 

Update SpecialPrice using DI API - XML

Former Member
0 Kudos

Hi,

I want to update my SpecialPrices using the DI API, and exporting the object in a XML file.

This is my process:

1) When I click on add button, I retrieve the CardCode and the ItemCode (getbykey)

2) I save the object like XML (specialPrice.SaveXML(pathXml)

3) I retrieve the object with (.getasxml) and replace the old value with the new value (.replace(oldvalue,newvalue)

4) I write the new xml

5) I set new obejct with GetBusinessObjectFromXML(path,0) and then I call .update() but I catch an error (invalid xml file)

What can I do??

Where is the error??

Regards

Marco

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Marco,

It seems the process looks ok so would it be possible to take a look at the source code? You don't have to post up your full add-on, just the section that reads, saves and uses the XML files. I'll use it to try and reproduce and troubleshoot.

Regards,

Niall

SAP Business One Forums

Former Member
0 Kudos

Thank Niall,

this is my code:

1) Save the oblect in XML file

//

Dim specialPriceFrom As SAPbobsCOM.SpecialPrices = myDB.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oSpecialPrices)

specialPriceFrom.GetByKey(code, cardCode)

specialPriceFrom.SaveXML(pathXml)

//

2) Retrieve and update file

//

Dim xmlmodel As String

myDB.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_AllNodes

xmlmodel = specialPriceFrom.GetAsXML()

xmlmodel = xmlmodel.Replace(specialPriceFrom.DiscountPercent, "1")

Dim str As StreamWriter = File.CreateText(pathXml)

str.Write(xmlmodel)

str.Close()

//

3) Import XML

//

myDB.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_ValidNodesOnly

Dim articoloTo As SAPbobsCOM.SpecialPrices = myDB.GetBusinessObjectFromXML(pathXml , 0)

ret = articoloTo.Update

//

Thank

Marco

Former Member
0 Kudos

Hi Niall,

Any news for me???

Thank

Marco

Former Member
0 Kudos

Marco, did you tried it without replacing the values? Try to update it with the same xml you got.

I think that thje problem is in

xmlmodel = xmlmodel.Replace(specialPriceFrom.DiscountPercent, "1")

Im persuaded, that with this replacing youll repalce other things too (names of nodes, ...).

The replacement should be somethink like

xmlmodel = xmlmodel.Replace("<node name>" & specialPriceFrom.DiscountPercent, "<nodename>1")

Try it and let me know.

Answers (0)