none
Code to write Custom logic once user add any item in custom list in SharePoint 2013 Online (Office 365 E3 version). RRS feed

  • Question

  • Hi,

     

    We need to write some custom logic once user add any item in custom list in SharePoint 2013 Online (Office 365 E3 version).

     

    Any approach, information, code about this would be greatly appreciated. Thanks!

    Monday, July 20, 2015 4:13 PM

Answers

  • Hi,

    Few different options:

    • Remote Event Receiver: downside is you need to host your code in a separate web site and since you don't have azure, the only option is a public web site hosting. And also complex in terms of development and expensive in terms of deployment.
    • Workflow: I think a custom workflow will be the best option but depends if your custom code logic can be implemented efficiently in workflow.
    • PreSaveAction: This is hacky solution and the function is not documented. So it might happen the hacky solution work today but if tomorrow Microsoft changes the implementation (say, function name is changed) and deploy, your code will not work. And it happens a lot in SP Online, if you don't follow the best practices/guidelines.

    So I would like to suggest to check workflow solution.


    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com

    Wednesday, July 22, 2015 6:01 AM

All replies

  • Overwrite PreSaveAction() in custom JavaScript when submitting SharePoint ListForms.
    You can add it content Editor webpart.
    Monday, July 20, 2015 7:24 PM
  • Thanks, can you please share some article for this
    Tuesday, July 21, 2015 6:01 AM
  • Hi Shailendra,

    There are two different approaches we can follow

    1) PreSaveAction() - Executing certains logics before saving the item to list

    https://social.technet.microsoft.com/Forums/sharepoint/en-US/86fe14fc-f353-4521-bf88-fd7fcabaa768/using-presaveaction-in-newformaspx-in-sharepoint-list?forum=sharepointgeneralprevious

    2) ItemAddedEvent Receiver - Execute custom logic after adding item to the list.

    http://onceinawhilescribble.blogspot.in/2013/05/creating-simple-event-receiver-in.html

    Thanks.


    A'Kumar

    Tuesday, July 21, 2015 6:33 AM
  • Hello Shailendra,

    You can add some JS logic in CEWP on your new/edit list forms something like below.

    <script src="/sites/dev/Style%20Library/Custom/Grid/jquery.min.js"></script>
    <script type="text/javascript">
    function PreSaveAction() {
        if ($("select[title='Status'] option:selected").val() == 'Closed') {
            alert("You can't reopen this item")
            return false;
        } else {
            return true;
        }
    }
    </script>

    Thanks.

    Tuesday, July 21, 2015 10:50 AM
  • Hi,

    Thanks, can we use this code in Sp13 Online version, also we don't have Azure?

    Tuesday, July 21, 2015 11:47 AM
  • Yes, you can use it in SP2013 Online.

    Thanks.

    Tuesday, July 21, 2015 1:33 PM
  • Thanks, what is option for post save action in SP2013 Online.
    Tuesday, July 21, 2015 3:07 PM
  • Hi,

    I suppose there is no method called PostSaveAction.

    If you wanna do certains action after saving the item, use event receiver or workflow based on your requiremnt.

    Thanks.


    A'Kumar

    Wednesday, July 22, 2015 3:57 AM
  • Hi,

    Few different options:

    • Remote Event Receiver: downside is you need to host your code in a separate web site and since you don't have azure, the only option is a public web site hosting. And also complex in terms of development and expensive in terms of deployment.
    • Workflow: I think a custom workflow will be the best option but depends if your custom code logic can be implemented efficiently in workflow.
    • PreSaveAction: This is hacky solution and the function is not documented. So it might happen the hacky solution work today but if tomorrow Microsoft changes the implementation (say, function name is changed) and deploy, your code will not work. And it happens a lot in SP Online, if you don't follow the best practices/guidelines.

    So I would like to suggest to check workflow solution.


    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com

    Wednesday, July 22, 2015 6:01 AM