Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Send different email body depending on field value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Send different email body depending on field value

    Hi
    I have a dialog that automatically sends a confirmation email upon submitting, working as expected.
    Now the customer wants to send then email in 2 possible languages, english and hebrew, but i still cannot accomplish it successfully.
    So, i added a Radio Button for the language, where the customer selects the language prior to submitting.

    So far, i did the following:
    1- tried to use the {ExecuteFunction:myFunc} in the html text in the send email action script, then defining a myFunc xbasic function that returns the correct html. The problem that i encountered is that although an e argument gets passed to the function, i cannot find e._currentRowDataNew for instance in order to check for the value of the field. In fact, debugging it, i found only e.tmpl has some data...

    2- tried therefore to use conditions in the html text, like in:
    {ConditionStart:English:{Language}="English"}...........english mail .........{ConditionEnd:English}
    {ConditionStart:Hebrew:{Language}="Hebrew"}..........hebrew mail .......{ConditionEnd:Hebrew}
    In both cases, i just get an empty mail ( in my opinion none of those conditions get kicked )

    Thanks in advance
    Jaime

    #2
    Re: Send different email body depending on field value

    You haven't given me much to go on here, but here's a start.

    In the dialog you would have a logical field for the language. You will also need to create a button for sending the email. In the OnClick for that button you can trap for the language logical and then send the appropriate email.

    Not sure I can help you more than that without seeing the dialog itself and how you have created this.

    Charlie

    Comment


      #3
      Re: Send different email body depending on field value

      Hi Charles
      Thanks for jumping in.
      As stated, i send the confirmation email upon submitting. This is done by going to the afterDialogValidate server side event, then after the "Save data..." i add a new Action Scripting and choose "Send EMail" from there. Then i fill the properties for the email, one of which is the HTML body which i'm talking about here.
      As for the language, i already have a radio-button field, which contains "English" or "Hebrew" depending on what the user filled.
      FWIW, i did some basic tests with the {ConditionStart} clauses, and it's like no matter what i do this placeholder doesn't do it's job.

      Jaime

      Comment


        #4
        Re: Send different email body depending on field value

        I have the same problem, seems like nothing will evaluate as true in the condition..

        Comment


          #5
          Re: Send different email body depending on field value

          Originally posted by Adrian_ View Post
          I have the same problem, seems like nothing will evaluate as true in the condition..
          Please post your code.
          Al Buchholz
          Bookwood Systems, LTD
          Weekly QReportBuilder Webinars Thursday 1 pm CST

          Occam's Razor - KISS
          Normalize till it hurts - De-normalize till it works.
          Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
          When we triage a problem it is much easier to read sample systems than to read a mind.
          "Make it as simple as possible, but not simpler."
          Albert Einstein

          http://www.iadn.com/images/media/iadn_member.png

          Comment


            #6
            Re: Send different email body depending on field value

            http://msgboard.alphasoftware.com/al...on-Not-working

            Comment


              #7
              Re: Send different email body depending on field value

              I couldn't get the conditions to work also.
              But you can convert the action to xbasic and make the changes then to get what you want.

              Comment


                #8
                Re: Send different email body depending on field value

                Could you give an example if possible please?

                Comment


                  #9
                  Re: Send different email body depending on field value

                  This is the xbasic from an action in the afterDialogValidate server-side event in a dialog component:
                  You will have to figure out how to change the contents of messageBodyHTML
                  if e.datasubmitted.language = "A" then
                  messageBodyHTML = "language A"
                  else messageBodyHTML = "language normal"
                  end if

                  So you create your action event as normal and then instead of editing the event you choose convert to xbasic and change what you want to change.


                  dim pe as p
                  with pe
                  DIM useDefaultSettings as L = .T.
                  DIM smtp_server as C
                  DIM smtp_username as C
                  DIM smtp_password as C
                  DIM smtp_port as C
                  DIM smtp_SSLOption as C
                  DIM from as C = "{sent_from}"
                  DIM from_alias as C = "{from_alias}"
                  DIM messageSubject as C = "{subject}"
                  DIM sendTo as C = "{Sent_to}"
                  DIM cc as C = "{cc}"
                  DIM bcc as C = "{bcc}"
                  DIM loadMessageFromRepository as L
                  DIM messageNameInRepository as C
                  DIM messageBodyHTML as C = "html message {KONTRAKT_nummer} etc"
                  DIM messageBodyText as C = "plain text {KONTRAKT_nummer}"
                  DIM attachments as C = "{file1},{file2}"
                  DIM storeMessageInOutbox as L
                  DIM clientSideEvent as P
                  DIM clientSideEvent.afterMessageSent as C
                  DIM showConfirmationMessage as L = .T.
                  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

                  '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 = <<%txt%
                  var obj = {};
                  obj.messageWasSent = __msgSent__;
                  obj.errorRext = '__errorText__';
                  if(window['__functionName__']) window['__functionName__'].call(this,obj);
                  %txt%
                  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

                  Comment

                  Working...
                  X