Page 1 of 1

Getting Smartfreight results

PostPosted: Tue Feb 07, 2023 2:51 pm
by DannyC
In the IFS Smartfreight plugin is this line which gets the response from Smartfreight when submitted - typically writing in the connote.
Code: Select all
Dim result As String = smartFreight.Import(smartFreightid, smartFreightpassword, salesOrderForm.SalesOrder.InvoiceNo, conNote.Serialise.InnerXml)


I'd like to write the result as an XML file to disk.
I have no problem writing a string to disk but how can I convert the result to a legible XML file?

Re: Getting Smartfreight results

PostPosted: Tue Feb 07, 2023 3:30 pm
by Mike.Sheen
start with simply writing it to file:

Code: Select all
System.IO.File.WriteAllText("Result.xml", result);


Is that not valid XML? If not, then what does the contents of the result variable look like?

Re: Getting Smartfreight results  Topic is solved

PostPosted: Tue Feb 07, 2023 3:35 pm
by Mike.Sheen
I just looked in the plugin and the line below where it gets the response, it loads the string into an XmlDocument:

Code: Select all
Dim xmlDocument As New System.Xml.XmlDocument
xmlDocument.LoadXml(result)


So, you should be able then call .Save on the xmlDocument:

Code: Select all
xmlDocument.Save("C:\myfile.xml")

Re: Getting Smartfreight results

PostPosted: Tue Feb 07, 2023 3:41 pm
by SBarnes
Code: Select all
string FormatXml(string xml)
{
     try
     {
         XDocument doc = XDocument.Parse(xml);
         return doc.ToString();
     }
     catch (Exception)
     {
         // Handle and throw if fatal exception here; don't just ignore them
         return xml;
     }
 }


and in vb

Code: Select all
Private Function FormatXml(ByVal xml As String) As String
    Try
        Dim doc As XDocument = XDocument.Parse(xml)
        Return doc.ToString()
    Catch __unusedException1__ As Exception
        Return xml
    End Try
End Function

Re: Getting Smartfreight results

PostPosted: Tue Feb 07, 2023 4:08 pm
by DannyC
Awesome.

This did it
Code: Select all
xmlDocument.Save("C:\myfile.xml")