I am in need of assistance. I've looked at this for far too long and I think a fresh set of eyes will help. I have a grid that has a button at the top to start emailing invoices to all the records in that grid. If first calls the function at the end of this code to go to the first record in the grid (just in case the user clicks to a different record in the grid). Then it calls the StartEmails function which incorporates the emailnew function. This worked fine at one point but I don't know why now I get an error as shown. It is supposed to create the pdf file of the invoice, then attach that to an email using a pre-defined gmail account that has been set up, and then move the next record and so forth and so on. It acts like it can't find the report but it does exist. Anyone who can help me, I would greatly appreciate it.
Error.jpg
Error.jpg
Code:
function StartEmails as c (e as p) dim deltempfile as c deltempfile = file.shortname_to_longname(file.temp_path_get()) dim delrfile as c delrfile = deltempfile+"Invoice.pdf" a5_file_remove(delrfile) dim CurrRows as n CurrRows = e.__si.RecordCount dim x as n x = 1 While x <= CurrRows dim jscmd as c = "" jscmd = <<%js% var rowNum = {grid.object}._selectedRow; {grid.Object}.ajaxCallback('G',rowNum,'emailnew','','_getData=true',{}); {grid.Object}.setFocus(rowNum+1); %js% StartEmails = StartEmails + jscmd x = x + 1 end while end function function emailnew as c (e as p) dim tempfile as c tempfile = file.shortname_to_longname(file.temp_path_get()) dim rfile as c rfile = tempfile+"Invoice.pdf" dim invnum as n invnum = convert_type(e._currentRowDataNew.Invoice_Number,"N") dim args as sql::Arguments dim Options as p dim printOptions as p args.set("blank", "") args.set("arg_InvNum",invnum) options.propogateErrors = .t. printOptions.blank = "" reportname = "Email_Invoice@rims_web.alb" saveAS = "PDF" filter = "Invoice_Number = :arg_InvNum" order = "" filename = rfile a5w_report_saveAs(reportName,saveAs,filter,order,filename,global_variables(),printOptions,args,options) 'send e-mail dim pe as p with pe DIM useDefaultSettings as L = .F. DIM smtp_server as C = a5w_getfromwebapprepository("smtp_server") DIM smtp_username as C = a5w_getfromwebapprepository("username") DIM smtp_password as C = a5w_getfromwebapprepository("password") DIM smtp_port as C = a5w_getfromwebapprepository("port") DIM smtp_SSLOption as C = "SSL" DIM from as C = a5w_getfromwebapprepository("email_address") DIM from_alias as C = a5w_getfromwebapprepository("alias") DIM messageSubject as C = "McLaurin Parking Company Account #: "+e._currentRowDataNew.Account_Number+" Invoice #: "+e._currentRowDataNew.Invoice_Number DIM sendTo as C = e._currentRowDataNew.Email_Address DIM cc as C DIM bcc as C DIM loadMessageFromRepository as L DIM messageNameInRepository as C DIM messageBodyHTML as C= "<p><font color=#000080 face=Arial>Dear Customer,<br>Please find attached your latest parking invoice. You can pay this via check or online at <a href='http://www.mclaurinparking.com'>www.mclaurinparking.com</a>.<br>PLEASE NOTE: If you have already made a payment for this invoice and it has been received, the account balance on the invoice will reflect this.<br>The account balance will reflect any pre-payments, credits, and/or outstanding previous balances.<br>You can also register for online access to view your account information and get copies of invoices, receipts, and statements. To register, click on 'Login' from our website and then click the registration link. Fill out the registration form. If no errors are given when you click submit, the registration form will close and you can immediately login.<br>Thank you for your business!<br>McLaurin Parking Co.</font></p>" DIM messageBodyText as C DIM attachments as C attachments = rfile DIM storeMessageInOutbox as L = .T. DIM clientSideEvent as P DIM clientSideEvent.afterMessageSent as C DIM showConfirmationMessage as L = .F. DIM confirmationMessageSuccess as C = "Message was sent." DIM confirmationMessageFailure as C = "Message was not sent because of an error." DIM useDotNetLibrary as L DIM sendWhen as C = "Immediate" DIM WorkQueueFormat as C = "XbasicScript" end with 'debug(1) 'resolve any property values that must be read from the repository a5_resolveRepositoryProperties(pe) dim flagError as l = .f. dim errorText as c = "" dim pEmailSettings as p dim pstore as p if pe.useDefaultSettings = .t. then dim pwp as p pwp = a5_getWebProjectProperties() if eval_valid("pwp.email") = .f. then flagError = .t. errorText = "Email settings not found" pStore.wasSent= "No" pStore.errorText=errorText else pEmailSettings = pwp.email end if else pEmailSettings.smtp_server = pe.smtp_server pEmailSettings.smtp_username = pe.smtp_username pEmailSettings.smtp_password = pe.smtp_password pEmailSettings.smtp_port = pe.smtp_port pEmailSettings.smtp_SSLOption = pe.smtp_SSLOption end if dim pMessageSettings as p dim isHTML as l = .f. if pe.loadMessageFromRepository then dim key as c key = pe.messageNameInRepository message = a5w_GetFromWebAppRepository(key) 'determine if the message is HTML by looking for a closing tag if atc("</",message) then pMessageSettings.html_message = a5_resolve_placeHolders_in_text(message,e,.t.) pMessageSettings.message = "" else pMessageSettings.html_message = "" pMessageSettings.message = a5_resolve_placeHolders_in_text(message,e,.f.) end if else 'message is NOT being loaded from repository pMessageSettings.html_message = a5_resolve_placeHolders_in_text(pe.messageBodyHTML,e,.t.) pMessageSettings.message = a5_resolve_placeHolders_in_text(pe.messageBodyText,e,.f.) end if pMessageSettings.send_to = a5_resolve_placeHolders_in_text(pe.sendTo,e,.f.) pMessageSettings.subject = *html_to_text(a5_resolve_placeHolders_in_text(pe.messageSubject,e,.t.)) pMessageSettings.attachments = a5_resolve_placeHolders_in_text(pe.attachments,e,.f.) pMessageSettings.cc = a5_resolve_placeHolders_in_text(pe.cc,e,.f.) pMessageSettings.bcc = a5_resolve_placeHolders_in_text(pe.bcc,e,.f.) pMessageSettings.from = a5_resolve_placeHolders_in_text(pe.from,e,.f.) pMessageSettings.from_alias = *html_to_text(a5_resolve_placeHolders_in_text(pe.from_alias,e,.t.)) pMessageSettings.lRelated = .f. pMessageSettings.ReturnReceipt = .f. 'if action does not define the sender, then read from saved email settings if pe.useDefaultSettings then if pMessageSettings.from = "" then pMessageSettings.from = pEmailSettings.from end if if pMessageSettings.from_alias = "" then pMessageSettings.from_alias = pEmailSettings.from_alias end if end if dim flagAutowrap as l = .t. dim pFlagSent as p dim flagUseDotNetLibrary as l flagUseDotNetLibrary = pe.useDotNetLibrary if flagError = .f. then 'there was no error in retrieving the email settings 'now, do the work - send the e-mail dim SSLOption as c SSLOption = pEmailSettings.smtp_SSLOption If pe.sendWhen = "Immediate" then pFlagSent = email_send_noprofile(pEmailSettings,pMessageSettings,SSLOption,flagAutowrap,flagUseDotNetLibrary) flagError = pFlagSent.error errorText = pFlagSent.errorText if flagError = .f. then pStore.wasSent= "Yes" pStore.errorText="" else pStore.wasSent= "No" pStore.errorText=errorText end if else 'add to WorkQueue dim workData as c if pe.WorkQueueFormat= "XbasicScript" then 'store xbasic script dim pMessageSettingsText as c pMessageSettingsText = alltrim(*variable_to_script(pMessageSettings)) pMessageSettingsText = *for_each(x,chr(9) + x, pMessageSettingsText) dim pEmailSettingsText as c pEmailSettingsText = alltrim(*variable_to_script(pEmailSettings)) pEmailSettingsText = *for_each(x,chr(9) + x, pEmailSettingsText) workData = "Dim pEmailSettings as P" +crlf()+\ "with pEmailSettings" + crlf()+\ pEmailSettingsText+\ "end with" + crlf(2) +\ "dim pMessageSettings as P"+crlf()+\ "with pMessageSettings" + crlf()+\ pMessageSettingsText + \ "end with" + crlf(2)+\ "dim SSLOption as c" + crlf()+\ "ssLOption = " + s_quote(SSLOption)+crlf()+\ "dim flagAutoWrap as l" + crlf()+\ "flagAutoWrap = " + s_quote(flagAutowrap)+crlf()+\ "dim flagUseDotNetLibrary as l" + crlf()+\ "flagUseDotNetLibrary = " + s_quote(flagUseDotNetLibrary) + crlf(2)+\ "pFlagSent = email_send_noprofile(pEmailSettings,pMessageSettings,SSLOption,flagAutowrap,flagUseDotNetLibrary)" else if pe.WorkQueueFormat = "XbasicProperties" .or. pe.WorkQueueFormat = "JSON" then 'store xbasic properties dim pWorkProperties as p pWorkProperties.pEmailSettings = pEmailSettings pWorkProperties.pMessageSettings = pMessageSettings pWorkProperties.sslOption = SSLOption pWorkProperties.flagAutoWrap = flagAutowrap pWorkProperties.flagUseDotNetLibrary = flagUseDotNetLibrary if pe.WorkQueueFormat = "XbasicProperties" then workData = property_to_string(pWorkProperties) else if pe.WorkQueueFormat = "JSON" then workData = vartojson(pWorkProperties) end if end if dim pWork as p pWork.id = api_uuidcreate() pWork.workData = workData dim flag as l dim pResult as p flag = a5w_SaveToWorkQueue(pWork,pResult) pstore.wasSent = "Yes" pstore.errorText = "" end if end if 'store message in outbox if pe.storeMessageInOutbox = .t. then pStore.dateStamp = now() pStore.subject = pMessageSettings.subject pStore.sent_by = pMessageSettings.from pStore.sent_by_alias = pMessageSettings.from_alias pStore.sendto = pMessageSettings.send_to pStore.cc = pMessageSettings.cc pStore.bcc = pMessageSettings.bcc pStore.attachments = pMessageSettings.attachments pStore.comments = "" if pMessageSettings.html_message <> "" then pStore.message = pMessageSettings.html_message else pstore.message = pMessageSettings.message end if dim flagMessageWasSavedInOutbox as l dim pResult as p 'If an error occurs, pResult.errorText will contain the reason for the error. flagMessageWasSavedInOutbox = a5_SaveToWebAppEmailOutBox(pStore,pResult) end if 'send Javascript back to browser to invoke client side method and display confirmation alert if pe.clientSideEvent.afterMessageSent <> "" then 'Send back a javascript command to invoke the function dim jsInvokeEvent as c jsInvokeEvent = <<%longstring% var obj = {}; obj.messageWasSent = __msgSent__; obj.errorRext = '__errorText__'; if(window['__functionName__']) window['__functionName__'].call(this,obj); %longstring% jsInvokeEvent = stritran(jsInvokeEvent,"__functionName__",pe.clientSideEvent.afterMessageSent) jsInvokeEvent = stritran(jsInvokeEvent,"__msgSent__", iif( convert_type(pstore.wassent,"L") ,"true","false") ) jsInvokeEvent = stritran(jsInvokeEvent,"__functionName__", js_escape(pStore.errorText) ) 'add the Javascript command to e.Javascript - the variable that contains all of the Javascript to be sent back to the browser. dim e.Javascript as c = default "" e.Javascript = e.Javascript + ";" + crlf() + jsInvokeEvent end if if pe.showConfirmationMessage = .t. 'Send back a javascript command to display the confirmation messge dim jsAlert as c dim msg as c if convert_type(pstore.wasSent,"L") then msg = pe.confirmationMessageSuccess else msg = pe.confirmationMessageFailure end if jsAlert = "alert('" + js_escape(msg) + "');" 'add the Javascript command to e.Javascript - the variable that contains all of the Javascript to be sent back to the browser. dim e.Javascript as c = default "" e.Javascript = e.Javascript + ";" + crlf() + jsAlert end if 'Return a Javascript command 'emailnew = "alert('You submitted a value of: " + js_escape(e._currentRowDataNew.lastname) + "');" 'emailnew = e.Javascript a5_file_remove(rfile) end function function GoToFirstRec as c (e as p) dim jscmd as c jscmd = <<%js% {grid.Object}.setFocus(1); %js% GoToFirstRec = jscmd end function