Export file to shared folder  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Export file to shared folder

Postby Riyaz » Thu Nov 11, 2021 7:17 pm

Hi There

Is it possible to export a some documents such as Invoices, Purchase Orders, Some reports as PDFs to be saved under shared drives through a plugin.

Mean, map a selective shared drive in the plugin and save it there.
Riyaz
Kohai
Kohai
 
Posts: 254
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Export file to shared folder  Topic is solved

Postby SBarnes » Fri Nov 12, 2021 9:31 am

Below is the code out of the rest api that can create a pdf from a report that should be enough as a starting point


Code: Select all
public ServiceStack.Web.IHttpResult Get(ReportsPDFGETRequest request)
        {
            JiwaApplication.Manager manager = this.SessionAs<JiwaAuthUserSession>().Manager;

            JiwaApplication.Report.Configuration.ReportCollection m_Reports = manager.BusinessLogicFactory.CreateBusinessLogic<JiwaApplication.Report.Configuration.ReportCollection>(null);
            m_Reports.Read();

            // find report with request.ReportID
            JiwaApplication.Report.Configuration.Report report = m_Reports[request.ReportID];

            if (report == null)
                throw new JiwaApplication.Exceptions.RecordNotFoundException("Report not found");

            JiwaApplication.JiwaPrintReport.JiwaPrintReport printReportObject = manager.BusinessLogicFactory.CreateBusinessLogic<JiwaApplication.JiwaPrintReport.JiwaPrintReport>(null);
            printReportObject.Setup();

            printReportObject.LoadReport(report);

            if (request.ReportParameters != null)
            {
                foreach (ReportParameter reportParameter in request.ReportParameters)
                {
                    foreach (JiwaApplication.JiwaPrintReport.JiwaReportRange jiwaReportRange in printReportObject.JiwaReportRangeCollection)
                    {
                        if (printReportObject.JiwaPrintFormulaCollection[jiwaReportRange.FormulaKey].Name.Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper() == reportParameter.Name.Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper())
                        {
                            jiwaReportRange.Value = reportParameter.Value;
                            break;
                        }
                    }
                }
            }

            printReportObject.UpdateReport();

            // export report to PDF
            string tempFolderPath = System.IO.Path.GetTempPath();
            string fileName = report.Title;

            // Make filename safe
            foreach (char c in System.IO.Path.GetInvalidFileNameChars())
            {
                fileName = fileName.Replace(c.ToString(), "");
            }

            string fullFileName = System.IO.Path.Combine(tempFolderPath, fileName) + ".pdf";
            printReportObject.CrystalReportObject.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, fullFileName);

            // Return the file
            System.IO.FileInfo fileInfo = new System.IO.FileInfo(fullFileName);
            return new HttpResult(fileInfo, asAttachment: request.AsAttachment);
        }
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Export file to shared folder

Postby Riyaz » Sat Nov 13, 2021 7:41 pm

Hi Stuart

Thanks for the same, prefer to do this via plugin, is that not possible?
Riyaz
Kohai
Kohai
 
Posts: 254
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Export file to shared folder

Postby Mike.Sheen » Sat Nov 13, 2021 7:49 pm

Riyaz wrote:Hi Stuart

Thanks for the same, prefer to do this via plugin, is that not possible?


Of course it is. Stuart's just provided the code from the REST API plugin that does what you need - you just need to grab the critical bits of code out of that.
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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Export file to shared folder

Postby SBarnes » Sun Nov 14, 2021 8:03 am

Thanks Mike, yes that was my intention.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Export file to shared folder

Postby Riyaz » Mon Nov 15, 2021 11:23 am

Thanks Mike & Stuart
Riyaz
Kohai
Kohai
 
Posts: 254
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Export file to shared folder

Postby Riyaz » Mon Nov 15, 2021 10:59 pm

Hi Mike and Stuart

Just further on this, it works fine for the reports but it wont if we try to save the sales order invoices, the printReportObject.LoadReport(report) wont accept it. It just throws the null error (Object reference not set)

Any suggestions pls
Riyaz
Kohai
Kohai
 
Posts: 254
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Export file to shared folder

Postby SBarnes » Tue Nov 16, 2021 7:39 am

Without seeing the actual code it is largely impossible to comment can you post a copy of the plugin in question?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Export file to shared folder

Postby Riyaz » Tue Nov 16, 2021 2:04 pm

Sorry thought had attached it, here it is
Attachments
Plugin Salesorder test.xml
(34.7 KiB) Downloaded 1530 times
Riyaz
Kohai
Kohai
 
Posts: 254
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Export file to shared folder

Postby SBarnes » Tue Nov 16, 2021 3:40 pm

Trying to print a report in the save start in never going to work as you can't run a crystal report for data that isn't in the database i.e. Jiwa has not saved the data yet.

The first step would be to change the event you are attaching to.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Next

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 1 guest