QuickBooks accept entries but ignores value on close

I have a script that is supposed to set a closing statement date and the closing balance of an account into a drop down box in QuickBooks. The result should show all entries up to the closing statement date and the ending balance of the account as entered. The following script enters the date and the closing balance. I have tried to make sure the date is a date but that did not help.

I am using QuickBooks for Mac 2019.


tell application "QuickBooks 2019"
	activate
	tell application "System Events"
		tell process "QuickBooks 2019"
			click menu item "Reconcile " of menu 1 of menu bar item "Banking" of menu bar 1
			delay 2
			--Set Date
			set ansDate to display dialog "Enter Statement Date in the format mm/dd/yy" default answer ""
			set Stmdate to text returned of ansDate
			--convert the string to a date
			set thedate to current date
			tell thedate to set {its month, its day, its year} to words of Stmdate
			set thedate to short date string of (thedate)
			display dialog thedate
			set value of text field 2 of group 1 of sheet 1 of window "Reconcile" to thedate as string
			--Set Closing Balance
			select text field 1 of group 1 of sheet 1 of window "Reconcile"
			delay 1
			set ansBal to display dialog "Enter closing Balance of Statement" default answer ""
			set StmBal to text returned of ansBal
			set value of text field 1 of group 1 of sheet 1 of window "Reconcile" to StmBal as string
			delay 1
			--click button "OK" of sheet 1 of window "Reconcile"
		end tell
	end tell
end tell

I do not have “QuickBooks 2019”, so I have not tested script, but in my opinion your dialogs should be outside the tell application “System Events”… block:


set Stmdate to text returned of ¬
	(display dialog "Enter Statement Date in the format mm/dd/yy" default answer "04/03/2020")
--convert the string to a date
set thedate to (current date)
tell thedate to set {its month, its day, its year} to words of Stmdate
set thedate to short date string of (thedate)
display dialog thedate

set StmBal to text returned of (display dialog "Enter closing Balance of Statement" default answer "")

tell application "QuickBooks 2019" to activate
tell application "System Events" to tell process "QuickBooks 2019"
	click menu item "Reconcile " of menu 1 of menu bar item "Banking" of menu bar 1
	repeat until sheet 1 of window "Reconcile" exists
		delay 0.02
	end repeat
	tell window "Reconcile" to tell sheet 1
		--Set Date 
		set value of text field 2 of group 1 to thedate
		--Set Closing Balance
		select text field 1
		set value of text field 1 of group 1 to StmBal
		delay 1
		click button "OK"
	end tell
end tell

You may try :


set StmDate to my defineDate("Enter Statement Date in the format mm/dd/yy")

set StmBal to my defineDate("Enter closing Balance of Statement in the format mm/dd/yy")

tell application "QuickBooks 2019" to activate
tell application "System Events" to tell process "QuickBooks 2019"
	click menu item "Reconcile " of menu 1 of menu bar item "Banking" of menu bar 1
	repeat until sheet 1 of window "Reconcile" exists
		delay 0.02
	end repeat
	tell window "Reconcile" to tell sheet 1
		tell group 1
			-- As I don't have the app, I'm not sure if the targets are text fields or combo boxes
			if class of UI elements contains text field then
				set target1 to text field 1
				set target2 to text field 2
			else
				set target1 to combo box 1
				set target2 to combo box 2
			end if
			--Set Date 
			select target2
			set value of target2 to StmDate
			--Set Closing Balance
			select target1
			set value of target1 to StmBal
		end tell -- group 1
		delay 1
		click button "OK"
	end tell
end tell

on defineDate(prompt)
	repeat
		set myDate to text returned of (display dialog prompt default answer "04/03/2020")
		set {theMonth, theDay, theYear} to words of myDate
		-- minimal test of validity
		considering numeric strings
			if (theMonth < "13") and theDay < "32" then exit repeat
		end considering
		beep
	end repeat
	set thedate to (current date)
	tell thedate to set {its month, its day, its year} to {theMonth, theDay, theYear}
	set thedate to short date string of (thedate)
	-- display dialog theDate -- you may enable it if you want
	return thedate
end defineDate

Matter of safety it check that both dates match the wanted format.
Matter of safety too, it check the nature of the target items supposed to receive the dates.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 3 mai 2020 11:37:33