1. Tracy Lamb
  2. PowerBuilder
  3. Monday, 8 July 2024 19:21 PM UTC

Hi all,

My customer reported an issue today with merging dw's and pdf's.  In the main window, he opens a salesorder with 100 workorders, then selects the Merge Each radio button and clicks Merge on the toolbar.  The merge function loops through each workorder and merges the associated documents then saves.  wf_merge_each loops through, calling wf_merge_one on each pass.  Customer said if he does something else, like open Word or Excel, while he's waiting, wf_merge_each doesn't merge all 100 workorders.  

Here's the code for the two windows functions:

//wf_merge_each
integer li_CertCount, li_ThisCert, li_x, li_rc

//Loop through all of the Certs in the ddlb
li_CertCount = ddlb_certs.TotalItems()
for li_x = 1 to li_CertCount
	ddlb_certs.SelectItem(li_x)
	ddlb_certs.Event SelectionChanged(li_x)
	li_rc = wf_merge_one()
	if li_rc = -1 then
		return
	end if
next
//wf_merge_one
PDFDocument lpdf_doc
string ls_docName, ls_filename, ls_docDir
long ll_rowcount, ll_thisrow, ll_attachmentCount, ll_thisAttachment, ll_rc

ib_cancel = FALSE
lpdf_doc = Create PDFDocument

//Add Cert to PDF and/or Maintenance Record to pdf
if dw_1.RowCount() > 0 then
	ll_rc = lpdf_doc.importdatawindow( dw_1)
end if

if cbx_maintenance.checked then
	if dw_2.RowCount() > 0 then
		ll_rc = lpdf_doc.importdatawindow( dw_2 )
	end if
end if

// Add attachments
ll_attachmentCount = dw_attachments.Retrieve(il_WorkOrder)
ls_fileName = is_pdfSO + "Cert" + string(il_workorder) + ".pdf"
if ll_attachmentCount > 0 then
	ls_docDir = is_docDir + string(il_workorder) + '\'
	for ll_thisAttachment = 1 to ll_attachmentCount
		ls_docName = ls_docDir + dw_attachments.GetItemString(ll_ThisAttachment, "filename")
		// Check to see if document exists
		if FileExists(ls_docname) then
			ll_rc = lpdf_doc.importpdf( ls_docName )
		else
			ll_rc =MessageBox("Merge Documents", "The following attachment does not exist:~r~n" + ls_docname + "~r~nContinue?", Question!, YesNo!)
			if ll_rc = 2 then
				destroy lpdf_doc
				RETURN -1
			end if
		end if
	next
end if

ll_rc = lpdf_doc.save( ls_filename )
if ll_rc < 0 then
	MessageBox("Save Error", "An error occurred saving the merged PDF file.~r~nError: " + string(ll_rc), StopSign!)
end if

destroy lpdf_doc

return 1


It works fine if he does not do something else in the meantime.  Any advice?

~~~Tracy

 

Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 8 July 2024 19:35 PM UTC
  2. PowerBuilder
  3. # 1

"Does not do something else" ... to me this sounds like possibly the "something else" changes the current directory of windows.

Before you run the code, do a GetCurrentDirectory() and save it in a string. Then before working with the next file make sure to set it back using ChangeDirectory().

regards

Comment
  1. Tracy Lamb
  2. Monday, 8 July 2024 20:41 PM UTC
That's a good idea, but I do set the variable is_pdfSO to the application directory in the window's open event, so that wouldn't change.

  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 8 July 2024 21:04 PM UTC
  2. PowerBuilder
  3. # 2

Hi Tracy;

  I would disable the entire App. For example - disabling the MDI Window - so that all menus, windows, controls, etc are locked out while the "merge function" process is on going. Of course, setting the mouse pointer into a wait state beforehand. You can display the progress of the "merge function" process in the MDI windows "microhelp" status bar. Then when the process has completed, enable the Apps MDI Window.

  That will stop the App user from trying to start another process until this critical processing has completed. Food for thought. HTH 

Regards ... Chris 

Comment
There are no comments made yet.
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Tuesday, 9 July 2024 06:53 AM UTC
  2. PowerBuilder
  3. # 3

"Does not do something else" 
1.  Is that within the application or outside of the application?  

Nevertheless
1.  Have you tried with yield() command inside the loop?
2.  Have you tried with Try .... Catch command to catch any runtime errors ?  That might give you an idea of on what ground the error pops out.

Happiness Always
BKR Sivaprakash

 

Comment
  1. René Ullrich
  2. Tuesday, 9 July 2024 11:31 AM UTC
Sounds like a bug. You should open a support ticket.
  1. Helpful
  1. Sivaprakash BKR
  2. Wednesday, 10 July 2024 06:03 AM UTC
Check whether you have sufficient RAM. If yes, then it might be a bug, as Rene Ullrich says.

  1. Helpful
  1. Chris Pollach @Appeon
  2. Wednesday, 10 July 2024 11:35 AM UTC
Hi BKR;

That is a good suggestion. If there is a good amount of RAM, then another good test might be to try compiling the App into a 64 bit EXE. Then the address space would be a lot larger at runtime.

Regards .. Chris
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.