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

I'm so close! Help with setting up a loop to generate viewbox for bulk emailing.

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

    I'm so close! Help with setting up a loop to generate viewbox for bulk emailing.

    I have received help from many on the forum concerning this subject.

    I've got a UX with a list of email recipients (it is pulled from a SQL query that filters based on certain criteria). When a list row is selected, a viewbox with an email message is populated. Wanting to have a bulk mail solution that sends individual, personalized emails to each member of the email recipient list with one button click.

    I have been using an "it works" solution that successfully generates the viewbox, pulls the HTML from viewbox, and sends the email via SparkPost. It isn't ideal as I have to manually select the row in a list (I sent about 500 emails earlier this week, manually clicking through), then press a send button. I figured out a way to eliminate the button press, but in the ideal world I would open the UX which would generate the list of email recipients and then press a "go" button that loops through each recipient, generates the unique viewbox with the email text, sends the HTML back to the xbasic, and then sends the email to each one. I am sure a loop is possible, and many posts on the forum even state that the loop is the easy part. Well, I've been trying to figure this out for the better part of a year (when I had free time) and I'm still stuck.

    Basically, in debug I can see that my loops is successfully iterating through the list of recipients, but something about the way I pull the innerHTML into xbasic is not updating the viewbox data for each iteration of the list - so the HTML for the email remains the same as the first recipient for all people on the list.

    Code:
    function sendmail as c (e as p)
    
    dim p as p
    p = json_parse(e._listData)
    for each donor in p
    e._set.id.value = donor.w_sponsor_id
    e._set.names.value = donor.w_sponsor_id
    dim js as c = ""
    
    dim email as c
    email = ""
    email = donor.email
    dim ix as n
    dim tmpl as p
    tmpl = e.tmpl
    ix = tmpl.page_fields.findi("vb","v.variablename")
    if ix > 0 then
    dim json as c
    json = tmpl.page_fields[ix].v.viewbox.definitionJSON
    dim p as p
    p = json_parse(json)
    dim css as c
    css = p.formview.css
    end if
    
    dim html as c = ""
    html = "<html><head><style>" + css + "</style></head><body>" + crlf() + e._html + "</body></html>
    dim MyOrganizationEmailAddress as c = "[email protected]"
    dim SparkpostKey as c = secret sparkpost key
    dim pm as p
    pm.send_to = email
    pm.from_name = "Some guy
    pm.from_email = MyOrganizationEmailAddress
    pm.subject = "Thank You"
    pm.message_html = html
    pm.attachments = "c:\A5Webroot\PC\Results.pdf"
    pm.message_text = ""
    
    'this property is very important. if you don't set this property the email message will not use the stylesheet
    pm.options.inline_css = .t.
    dim pResult as p
    'pResult = email_send_sparkpost(SparkpostKey,pm)
    sendmail = js
    next
    
    end function
    and the code that generates the HTML

    Code:
    var html = $('viewboxcontent').innerHTML;
    //var data = A5.ajax.buildURLParam('_html',html);
    var list = {dialog.object}.getListData('names');
    var dataJSON = JSON.stringify(list);
    var _dataToSubmit = A5.ajax.buildURLParam('_listData',dataJSON)+"&"+A5.ajax.buildURLParam('_html',html);
    {dialog.object}.ajaxCallback('','','sendmail','',_dataToSubmit);
    setTimeout(function(){
    alert('Here is what we sent:'+html);},2000);
    Any guidance? I find the documentation for Viewboxes less than helpful and I'm sure they are amazing and very powerful, but I'm just not experienced enough yet to figure this out.

    #2
    I stared at this yesterday and didn't feel like I could help. Maybe I can't today either, but I'll try. You've got an interesting mix of Javascript and XBasic I haven't used before, a number of functions I haven't used, and I'm not very familiar with Viewboxes... okay, I tried but I'm in over my head.

    My real question is why you need to generate a viewbox on each iteration? To "generate a viewbox" I think you're querying something to produce the HTML for the viewbox, yes? Can you just move that query within your loop and skip the viewbox creation altogether?

    Comment


      #3
      Can I skip the viewbox altogether? The short answer is probably. This is a weird, Frankenstein monster of a video I saw posted by alpha and a few other things I have curated together. I think I was aiming at first just to get an email to successfully send. Having the list and the viewbox combination was the easiest way I could find to have a nicely formatted HTML that allowed me to use a nested SQL query. Or at the very least, it was the way that I found online tutorials close enough to it. Honestly, it's over my head too, which is part of the problem. I tend to make these things more difficult for myself simply because I'm driving forward on a solution because I vaguely understand what I'm doing when the obvious solution might be significantly easier yet beyond my current knowledge. I have only been developing on the web side for a year and I'm self taught from this forum, IADN, and the alpha documentation.

      Does anyone know some simple code to generate HTML from text input, say a text area control? If I did away with the viewbox altogether it would be nice to be able to type in the email message text, maybe in a WYSIWYG editor. Since these emails are EOM giving summaries for a nonprofit, I would also still need to be able to have the nested SQL query, allowing for a one-to-many structure that doesn't send duplicate messages for a donor that gives more than once in a month. There is probably a better way to do that in sql as well, but since I've only been doing sql for about a year, I'm not certain.

      Any advice or help is appreciated!!

      Comment


        #4
        Okay I think I understand the goal now, why you're using a listbox, etc. Go back to the working version that you click a list row, it populates the viewbox, and then it automatically sends the email.

        What triggers the viewbox population when you click on a list row? There's some kind of Javascript or Action Javascript called? Maybe from the onSelect or onClick list event?

        Move that code to the list onSelect event.

        Just to start, add a button on the UX and put this code in the in click event (replace 2345 with the value of a primary key in the list):
        Code:
        {dialog.object}.setValue('YOURLISTNAME',2345)
        Does that select the list row, populate the viewbox, and send the email?

        If so, I think you could probably add your loop in Javascript rather than XBasic. I had to Google a little to add a delay within the loop, which I think is probably a good idea. So if the above code worked, you could change the code in your button to:


        Code:
        debugger;
        const delay = async (ms = 1000) =>
         new Promise(resolve => setTimeout(resolve, ms))
        
        var lObj = {dialog.object}.getControl('YOURLISTNAME');   // create a variable with the list object
        var numberOfRecords = lObj._data.length;   // get the length of the _data object of the list
        var primaryKey = 0;
        for (let ix = 0; ix < numberOfRecords; ix++) {  // ix is the index variable and will increase each iteration
          primaryKey = lObj._data[ix].__primaryKey;  // get the primary key value for the data index number ix
          {dialog.object}.setValue('YOURLISTNAME',primaryKey); // select the list row
          await delay(2000);  // browser will delay 2000 milliseconds before the next iteration
        }
        If you want a list that's filtered, you can use _rdata instead of _data.

        You could probably also replace the {dialog.object}.setValue('YOURLISTNAME',primaryKey); line with the code from the list onSelect event. It might complicate things a little, and I kindof liked seeing the list rows being selected.

        I don't know if you're familiar with Chrome Developer Tools, but open this in Chrome, hit F12 and then your UX button, and you can debug the Javascript.

        Comment


          #5
          Realized I never returned to share my outcome. I tried so many different things and finally realized I was making this whole process so much harder than I needed to. I don't regret it - I learned a lot about using Viewboxes and Lists that I would never have learned had I not went down the hundred wrong roads. (There's a life lesson in there somewhere).

          My final solution is the following:

          I have a UX with a list control and a text area input field. The list shows me the recipient list for this particular bulk mail, based on a particular filter. Incidentally, this filter is created by a date range and an xbasic function that runs a SQL update operation that sets a field "Mail Trigger" to true if the record meets filter criteria. then the user types their desired message into the text area, hits send and the rest is just an HTML email message built by xbasic and a couple nested for loops. I am getting exactly the result I saught and it's fairly straightforward.

          Thank you to everyone who has submitted input, feedback, and support throughout this year-long process. I am only a part-time developer, but this has been an exciting and challenging experience.

          Comment

          Working...
          X