none
Create new list item from the existing one

    Question

  • I have custom list on WSS 3.0. What I need now is the additional command "Clone this item" associated with any single item of the list (button on the Ribbon or item in the context menu). This command should display NewForm.aspx filled with values of the selected item. After that user can change any values and click Save (or Cancel) button. The point is that I don't want to create a new item in the list but to show "New Item" form as described above.

    What are smart ways to implement this feature? Thanks in advance.

    Tuesday, February 21, 2012 9:05 PM

Answers

  • Hi Alisher

    You can draw inferences about other cases from one instance. Add some Javascipt code used to parse the Url and assignment controls on your NewForm.aspx page.At the List Item page,you can only to add a button or link to jump to the NewForm.aspx with Some of the parameters.

    Thanks,
    Lhan Han

    Tuesday, February 28, 2012 2:10 AM
    Moderator

All replies

  •  

    Hi Alisher,

    You can achieve your requirement by modify the List Item’s AllItems.aspx page use SharePoint Designer(SPD). See the following steps:

    (My environment:MOSS2007 SP3,Windows Server2003,SharePoint Designer2007)

    1
    Create a Custom List on your SharePoint. Add a Hyperlink column to it(Used for passing parameters),set it to non-manually modify.
    2
    Use SPD to open the AllItems.aspx page of your List Item.
    3
    Add the Add Page SharePoint Control to the page.
    4
    Using Javascript dynamic modify the value of the Add Page Controls(include the Hyperlink value).When a control value changes automatically cascade to Hyperlink value ​​change.


    Here is the Javascript code of my sample(use Jquery):
    <script type="text/javascript" language="javascript">

        $(document).ready(function () {

            // ctl00_m_g_94729b61_e5f2_45d5_9f73_6719ac36f634_ff1_1_ctl00_ctl00_TextField   is the Title controls id, use IE delevoper tools get it

            // ctl00_m_g_94729b61_e5f2_45d5_9f73_6719ac36f634_ff2_1_ctl00_ctl00_UrlFieldUrl is the Hyperlink UrlField controls id, use IE delevoper tools get it

            // ctl00_m_g_94729b61_e5f2_45d5_9f73_6719ac36f634_ff2_1_ctl00_ctl00_UrlFieldDescription is the UrlDescriptionField controls id, use IE delevoper tools get it

            Assignment();

            AssignmentHyperlink();

            $("#ctl00_m_g_94729b61_e5f2_45d5_9f73_6719ac36f634_ff1_1_ctl00_ctl00_TextField").bind("blur", AssignmentHyperlink);

            $("#ctl00_m_g_94729b61_e5f2_45d5_9f73_6719ac36f634_ff2_1_ctl00_ctl00_UrlFieldUrl").bind("focus", function () { this.blur(); });

            $("#ctl00_m_g_94729b61_e5f2_45d5_9f73_6719ac36f634_ff2_1_ctl00_ctl00_UrlFieldDescription").bind("focus", function () { this.blur(); });

        }

            );

        function request(paras) {

            var url = location.href;

            var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");

            var paraObj = {}

            for (i = 0; j = paraString[i]; i++) {

                paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);

            }

            var returnValue = paraObj[paras.toLowerCase()];

            if (typeof (returnValue) == "undefined") {

                return "";

            } else {

                return returnValue;

            }

        }

        function Assignment() {

            try {

                var title = request("title");

                if (title) {

                    $("#ctl00_m_g_94729b61_e5f2_45d5_9f73_6719ac36f634_ff1_1_ctl00_ctl00_TextField").val(title);

                }

            }

            catch (e) { }

        }

        function AssignmentHyperlink() {

            var title = $("#ctl00_m_g_94729b61_e5f2_45d5_9f73_6719ac36f634_ff1_1_ctl00_ctl00_TextField").attr("value");

            if (!title) {

                title = "";

            }

            $("#ctl00_m_g_94729b61_e5f2_45d5_9f73_6719ac36f634_ff2_1_ctl00_ctl00_UrlFieldUrl").val("http://lhan-pc1:8081/sites/sites1/Lists/vlist3/AllItems.aspx?" + "title=" + title);// use your url

            $("#ctl00_m_g_94729b61_e5f2_45d5_9f73_6719ac36f634_ff2_1_ctl00_ctl00_UrlFieldDescription").val("Clone this item");

        }

        </script>

    The attachment is my sample’s list template, you can  download for reference:sample.stp

    How to use IE developer tools:
    http://msdn.microsoft.com/en-us/library/dd565626(v=vs.85).aspx

    Thanks,
    Lhan


    Thursday, February 23, 2012 10:05 AM
    Moderator
  • Thanks for idea, Lhan. The point is that your "solution" works on AllItems.aspx only. And what about the other views? What about any new view that will be created later by user?
    Monday, February 27, 2012 8:47 AM
  • Hi Alisher

    You can draw inferences about other cases from one instance. Add some Javascipt code used to parse the Url and assignment controls on your NewForm.aspx page.At the List Item page,you can only to add a button or link to jump to the NewForm.aspx with Some of the parameters.

    Thanks,
    Lhan Han

    Tuesday, February 28, 2012 2:10 AM
    Moderator