How do I send email notification to the users when content will update

usmanehsan0613's Avatar

usmanehsan0613

02 Nov, 2015 07:33 AM

Hello,

I need to send email notification to a list of users in my csv file whenever any page is updated. I will upload the csv file under root.

Here is the format of CSV

-> columns headings : username,email,firstname,lastname -> columns data : someuser,[email blocked],some,user

It should start reading the email address + name of the user and send emails . Let say i have updated the page under

about_website -> about_courses -> courses (page).

So upon updating the page it should fetch the title of page + its url link and send email.

Can you please help me in this as this is the major part of any CMS site like many wordpress sites are doing this. Its a requirement from our institute to keep the users updated.

Thanks & Best Regards Uthman

  1. 1 Posted by Ryan Griffith on 02 Nov, 2015 01:47 PM

    Ryan Griffith's Avatar

    Hi Uthman,

    To confirm, are the users within the CSV file always the same regardless of the page, or does the list vary depending on the page?

    Off-hand I think you could accomplish this in one of two ways:

    • Attach a CREATE/EDIT type Workflow that sends an email when a page is created or updated. The workflow would be slightly different if the recipients vary based on the page, but I think this still might be possible and we can discuss that further.
    • If you are willing to consider publishing the page an "update," you could use a custom publish trigger that calls an external script which reads your CSV file and emails accordingly. Again, if the recipients vary based on page you would need to tweak things a bit to determine who to send the email to, but it should be possible.

    Looking forward, we are discussing adding the ability for users to watch pages, which might help you in this case. Basically, anyone who wants to get an email about the page being updated would need to watch the page. This would in-turn allow them to opt out of being notified by un-watching. Also, with the addition of content owners, we are looking into adding more automated functionality to notify owners of assets.

    Here is a related suggestion on our Idea Exchange, please feel free to vote it up if you would like this feature to be considered for a future release.

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by usmanehsan0613 on 03 Nov, 2015 04:26 AM

    usmanehsan0613's Avatar

    Hello,

    The list stays same for each page for now. the second option might be useful for me

    " If you are willing to consider publishing the page an "update," you could use a custom publish trigger that calls an external script which reads your CSV file and emails accordingly. Again, if the recipients vary based on page you would need to tweak things a bit to determine who to send the email to, but it should be possible. "

    How can i implement the above. where should i place external script , i am interesting to use javascript / jquery to send the request to some external php script.

    Thanks,

  3. 3 Posted by Ryan Griffith on 03 Nov, 2015 01:20 PM

    Ryan Griffith's Avatar

    Hi Uthman,

    My initial thought for the second option would be a custom Publish Trigger that would be executed every time an asset is published. In this publish trigger, you would check the asset type and send out an email.

    where should i place external script , i am interesting to use javascript / jquery to send the request to some external php script.

    Thinking through this a bit more, we suggested something similar to a client not long ago that might be of use.

    To summarize:

    • Your page contains a Velocity Format that generates a block of JavaScript code wrapped with #protect and [system-view:internal] pseudo tags
    • The JavaScript calls an external script passing some data about the asset. I'm thinking ID, name, path, site, last modified timestamp, last modified by
    • The external script uses the passed data and compares it to a cache or lookup table to determine if a notification needs to be sent
    • If a notification should be sent, the script sends an email and updates the cache accordingly. I would say keep it simple where you use the ID as the key and lasy modified timestamp as the value.

    With this setup, the JavaScript would run each time the page is viewed and is only output/ran when viewing the page within Cascade (hence the [system-view:external] tag). The cache/lookup would avoid sending notifications unnecessarily.

    I like this setup because it's much easier to add a region to the bottom of your Templates and drop a Velocity Format in for pages you want to send notifications for as opposed to maintaining the publish trigger. The downside is you are restricted to only page assets.

    Please let me know if you have any questions.

    Thanks!

  4. 4 Posted by usmanehsan0613 on 04 Nov, 2015 04:18 AM

    usmanehsan0613's Avatar

    Hi,

    Can you please give me some example for such format. I am using xslt format .

    Thanks,

  5. 5 Posted by usmanehsan0613 on 04 Nov, 2015 04:22 AM

    usmanehsan0613's Avatar

    e.g in wordpress you would do something like

    add_action('save_post', 'send_email);

    function send_email()
    { // here i can do whatever stuff i need to do . with a simple hook. // it will execute this function after post / page is saved. }

    Would be great if you please give some quick and simple solution as we need to implement this quickly. Several days are passed and still no solution. Please help.

    Thankyou.
    Uthman

  6. 6 Posted by usmanehsan0613 on 04 Nov, 2015 08:55 AM

    usmanehsan0613's Avatar

    [system-view:external] or [system-view:internal]

    If we put some javascript that will execute everytime that will create another issue. I only need some javascript code to run whenever the page is published.

    Thanks,

  7. 7 Posted by Ryan Griffith on 04 Nov, 2015 03:07 PM

    Ryan Griffith's Avatar

    Hi Uthman,

    You would use [system-view:internal] so the code is only executed and output when viewing the page within Cascade.

    If we put some javascript that will execute everytime that will create another issue. I only need some javascript code to run whenever the page is published.

    As long as you use a caching system to check if the asset was updated after the cached timestamp, I don't foresee any major issues with the AJAX request executing each time the page is viewed. Are there other concerns you have?

    The only other way to accomplish this would be a custom Publish Trigger, which also has it's downsides. For instance, a publish trigger will be invoked for every publishable asset type and, for pages, every individual output (since it's a separate publish job).

    You could add a couple of checks to make sure the asset being published is a page and you are running the code for a single output, but you would still need a way to determine if the page was updated or not since a publish is not the same as an update. Similar to the JavaScript solution, you would need a means of recording the last time an email was sent to compare the asset's last modification time at the time of the publish.

    With that said, IMO the JavaScript solution would be the simplest to implement and maintain since it won't require compiling a publish trigger .jar, dropping it into the installation directory, and restarting Cascade. Additionally, the .jar needs to be re-added after upgrades.

    Would be great if you please give some quick and simple solution as we need to implement this quickly.

    Assuming you are already loading jQuery on your pages, you could drop the following Velocity Format into a region that is at the bottom of your Template to issue a POST to an external script (ie //domain.edu/script.php) and passing some data about the page:

    [system-view:internal]
    <script><![CDATA[#protect
    $.post('//domain.edu/script.php', {id: '${currentPage.identifier.id}', lastmodifiedon: '${currentPage.lastModified.time}', lastmodifiedby: '${currentPage.lastModifiedBy}' });
    #protect]]></script>
    [/system-view:internal]
    

    In your external script, you would use the asset's ID as a key for the lookup table and compare it to the cached last modified timestamp to see if the timestamp provided is newer. If it is newer, send an email and update the cache with the new timestamp.

    Please let me know if you have any questions.

    Thanks!

  8. 8 Posted by usmanehsan0613 on 05 Nov, 2015 08:10 AM

    usmanehsan0613's Avatar

    Hello,

    thanks for your detail reply.

    For custom publisher it will be more complex to implement as server is mantained by other department.

    For second option of using javascript / jquery ,I will not send email notification for each page rather i will fill a form within cascade having following fields.

    • Title
    • URL
    • Photo (if have any)
      • Last Updated time
      • Updated By (i.e username)

    and after filling this form i will submit and than jquery / javascript will post this information to some external script ie. domain.com/script.php , this script will do its job to send email notifications to all users.

    I think above is easy to implement within cascades. Actually i want to keep control within cascade.

    ** So what i need from you is to know how can I fetch the form information within cascades and pass this information as json object. **

    Hope above is clear and have a very easy solution.

    Thanks & Best Regards,
    Uthman

  9. 9 Posted by Ryan Griffith on 06 Nov, 2015 08:29 PM

    Ryan Griffith's Avatar

    Hi Uthman,

    What you can do is give the form an ID attribute (e.g. id="myform") and then you can use jQuery's serialize() method to serialize the form data to be sent to your script.

    If you are going this route, what you can do is output the form within your Velocity Format so you can essentially pre-fill the form. If you went this route, you could use hidden form fields with a submit button or link to submits the form, so you don't affect your page's markup too much.

    You would have something like the following in your Format for example:

    [system-view:internal]
    <form id="myform">
      <input type="hidden" name="id" value="${currentPage.identifier.id}"/>
      <input type="hidden" name="lastModifiedOn" value="${currentPage.lastModified.time}"/>
      <input type="hidden" name="lastModifiedBy" value="${currentPage.lastModifiedBy}"/>
      ...
    </form>
    <script><![CDATA[#protect
    $(document).ready(function() {
      var $form = $('#myform');
      $form.on('submit', function() {
        $.post('//domain.edu/script.php', $form.serialize());
        $form.replaceWith('<p>Notification sent.</p>');
        return false; 
      });
    });
    #protect]]></script>
    [/system-view:internal]
    

    Please let me know if you have any questions.

    Thanks!

  10. 10 Posted by usmanehsan0613 on 08 Nov, 2015 08:33 AM

    usmanehsan0613's Avatar

    Hi,

    In my format i tried following

     <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" extension-element-prefixes="date-converter" version="1.0" xmlns:date-converter="http://www.hannonhill.com/dateConverter/1.0/" xmlns:xalan="http://xml.apache.org/xalan">
        <!-- Xalan component for date conversion from CMS date format to RSS 2.0 pubDate format -->
        <form id="myform">
      <input type="hidden" name="id" value="${currentPage.identifier.id}"/>
      <input type="hidden" name="lastModifiedOn" value="${currentPage.lastModified.time}"/>
      <input type="hidden" name="lastModifiedBy" value="${currentPage.lastModifiedBy}"/>
     
    </form>
    
    </xsl:stylesheet>
    

    it throws error : Invalid XSLT: form is not allowed in this position in the stylesheet!

  11. 11 Posted by usmanehsan0613 on 08 Nov, 2015 08:34 AM

    usmanehsan0613's Avatar
  12. 12 Posted by usmanehsan0613 on 08 Nov, 2015 08:34 AM

    usmanehsan0613's Avatar

    I tried to put the form in xslt but it throws error.

  13. 13 Posted by Ryan Griffith on 09 Nov, 2015 02:13 PM

    Ryan Griffith's Avatar

    Hi Uthman,

    The code I provided is for a Velocity Format and not XSLT, this would explain the issue you are seeing.

    Simply copy the code I provided and the <form> markup you were using into a Velocity Format and apply it to your page region and that should do the trick.

    Please let me know if you have any questions.

    Thanks!

  14. 14 Posted by usmanehsan0613 on 10 Nov, 2015 05:15 AM

    usmanehsan0613's Avatar

    Hi Ryan,

    Can we say that <form> is not supported by XSLT in cascades as in other examples for XSLT it does supports form tag.

    I do prefer to use XSLT because in my whole site i am using XSLT format.

    Thanks,
    Uthman

  15. 15 Posted by Ryan Griffith on 11 Nov, 2015 08:18 PM

    Ryan Griffith's Avatar

    Hi Uthman,

    You can certainly use XSLT to accomplish this, I was just stating that you were combining Velocity code (i.e. $currentPage) with XSLT, which will not work. Also, your XSLT was not a valid Format.

    If you choose to use XSLT, you will need to apply a calling page Index Block along with the Format that also includes the asset's system metadata so you have access to the information you need.

    When you have a moment, give the following a try for starters and let me know how it goes:

     <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:template match="/system-index-block">
            <xsl:variable name="currentPage" select="calling-page/system-page"/>
            <form id="myform">
              <input type="hidden" name="id" value="{$currentPage/@id}"/>
              <input type="hidden" name="lastModifiedOn" value="{$currentPage/last-modified}"/>
              <input type="hidden" name="lastModifiedBy" value="{$currentPage/last-modified-by}"/>
            </form>
        </xsl:template>
    </xsl:stylesheet>
    

    Please let me know if you have any questions.

    Thanks!

  16. Ryan Griffith closed this discussion on 25 Nov, 2015 01:39 PM.

Discussions are closed to public comments.
If you need help with Cascade CMS please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

 

26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM