0

I want to auto fill the entries in form fields from previous entry in the sharepoint list

What I done is I created a new request from my custom form page and submit after that the data added in sharepoint list successfully

Now i created a data table for the request lists is visible in table format and created a button for each and every request to view the particular request.

when i click on that view button the form is open for that particular requests with all fields are disabled with data for that particular requests

Now i created a button name 'New' now there is two button 'submit' and 'new' i want that when i click on 'new' button same requests form data is auto filled in my custom form page from where we generate a new requests.

0

i assume that view form has ID of request in query string:

like this DispForm.aspx?ID=35&Source=...

so you can use own function to open New form with your query string for example NewForm.aspx?CopyID=35

In New form there will be function to cheeck if query string CopyID is present and if so, it will load Item with ID=35 from reuqests list and then prefill newform fields with loaded data. I have done this (with one exeption i loaded last created item).

Code after item is loaded (just to prefill standard newform):

$("td.ms-formbody").each(function(){    
    if($(this).html().indexOf('FieldInternalName="')<0) return; 
    var start = $(this).html().indexOf('FieldInternalName="')+19; 
    var stopp = $(this).html().indexOf('FieldType="')-6; 
    var internal_name = $(this).html().substring(start,stopp);
    if (internal_name=="INTERNAL NAME OF FIELD THAT SHOULD BE PREFILLED") {
        var stopp2 = stopp+17; 
        var field_type = "";
        while ($(this).html()[stopp2]!="\"") { /
            field_type += $(this).html()[stopp2];
            stopp2 += 1;
        }
        switch (field_type) {
            case "SPFieldText":
                if ($(this).find('input').length > 0) {
                    $(this).find('input').val(loaded_item.get_item(internal_name)); 
                }   
                break;
            case "SPFieldNote": //TextField_inplacerte (RichEdit enhaced text)
                if ($(this).find("div[id$='TextField_inplacerte']").length > 0) {
                    $(this).find("div[id$='TextField_inplacerte']").html(loaded_item.get_item(internal_name));
                }
                break;
            case "SPFieldChoice": 
                if ($(this).find('select option').length > 0) {
                    $(this).find('select option').each(function(){
                        if($(this).text() === loaded_item.get_item(internal_name)){
                            $(this).prop('selected',true).trigger("change");
                        }
                    });
                }
                break;
            default:
                console.log ("error"); return;
        }
    }
});

The code just checks all fields in newform (their internal_name), check if this field should be prefilled with loaded data (change "INTERNAL NAME OF FIELD THAT SHOULD BE PREFILLED") and then write that data in field.

Better approach could be to create own custom new form with html logic to better prefill data...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.