Getting Smartfreight results  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Getting Smartfreight results

Postby DannyC » Tue Feb 07, 2023 2:51 pm

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?
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Getting Smartfreight results

Postby Mike.Sheen » Tue Feb 07, 2023 3:30 pm

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?
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Getting Smartfreight results  Topic is solved

Postby Mike.Sheen » Tue Feb 07, 2023 3:35 pm

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")
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Getting Smartfreight results

Postby SBarnes » Tue Feb 07, 2023 3:41 pm

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
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Getting Smartfreight results

Postby DannyC » Tue Feb 07, 2023 4:08 pm

Awesome.

This did it
Code: Select all
xmlDocument.Save("C:\myfile.xml")
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 28 guests