Quantcast
Channel: SharePoint Legacy Versions - Using SharePoint Designer, InfoPath and Other Customizations Forum
Viewing all articles
Browse latest Browse all 2319

Copy List Item WITH Attachment to a new List Item in the same list

$
0
0

Hi all

i have found this Javascript in a Sharepoint Site which is used to duplicate the list item and create a new item in the same list. However i want to copy the attaachments too. I am not familiar with Javascript. Can someone please help me to correct this code so it also copies the attachments?

var pathname = window.location.pathname;
var paths = pathname.split("/");
var list = $().SPServices.SPListNameFromUrl();

$('table.ms-listviewtable tbody tr td:nth-child(4)').each(function () {
 var id = getRowId($(this));
 if(id){
  $(this).html('<a href="javascript:copyItem(' + id + ')"><img alt="Kopieren" src="/_layouts/images/copy.gif" border="0" /></a>');
  $(this).css("text-align", "center");
 }
});

function getRowId(element) {
 var row = $(element).closest('tr');
 var id = row.find('td:nth-child(3)').text();
 return id;
}

function copyItem(itemID) {
 $(document).ready(function() {
   try{  
  $().SPServices({
   operation: "GetListItems",
   async: false,
   listName: list,
   CAMLViewFields: "<ViewFields>" +
        "<FieldRef Name='Anmerkung' />" +
        "<FieldRef Name='Ausleitung_x0020_geplant' />" +
        "<FieldRef Name='Available_x0020_at' />" +
        "<FieldRef Name='Beschreibung' />" +
        "<FieldRef Name='Description' />" +
        "<FieldRef Name='Emailempf_x00e4_nger' />" +
        "<FieldRef Name='Emailkommentar' />" +
        "<FieldRef Name='Erfasst_x0020_am' />" +
        "<FieldRef Name='Legende' />" +
        "<FieldRef Name='Offener_x0020_Punkt_x0020_im_x00' />" +
        "<FieldRef Name='PRIO' />" +
        "<FieldRef Name='SA_x002F_Part_x0020_number' />" +
        "<FieldRef Name='SA_x002F_Teilebezeichnung' />" +
        "<FieldRef Name='_Status' />" +
        "<FieldRef Name='Verantwortlicher' />" +
        "<FieldRef Name='Verf_x00fc_gbar_x0020_zu' />" +
       "</ViewFields>",
   CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>" + itemID + "</Value></Eq></Where></Query>",
   completefunc: function (xData, Status) {
       //alert(xData.responseXML.xml);
        $(xData.responseXML).find("z\\:row").each(function() {
     
     var anmerkung = ($(this).attr("ows_Anmerkung"));
     var ausleitung = ($(this).attr("ows_Ausleitung_x0020_geplant"));
     var availableAt = ($(this).attr("ows_Available_x0020_at"));
     var beschreibung = ($(this).attr("ows_Beschreibung"));
     var description = ($(this).attr("ows_Description"));
     var emailempfaenger = ($(this).attr("ows_Emailempf_x00e4_nger"));
     var emailkommentar = ($(this).attr("ows_Emailkommentar"));
     var erfasstAm = ($(this).attr("ows_Erfasst_x0020_am"));
     var legende = ($(this).attr("ows_Legende"));
     var offenerPunkt = ($(this).attr("ows_Offener_x0020_Punkt_x0020_im_x00"));
     var prio = ($(this).attr("ows_PRIO"));
     var saPartNumber = ($(this).attr("ows_SA_x002F_Part_x0020_number"));
     var teileBezeichnung = ($(this).attr("ows_SA_x002F_Teilebezeichnung"));
     var status = ($(this).attr("ows__Status"));
     var verantwortlicher = ($(this).attr("ows_Verantwortlicher"));
     var verfuegbarZu = ($(this).attr("ows_Verf_x00fc_gbar_x0020_zu"));
   
     var batchCmd = "<Batch OnError='Continue'><Method ID='1' Cmd='New'>";
     
     if(anmerkung != undefined && anmerkung != null) {
      batchCmd += "<Field Name='Anmerkung'><![CDATA["+ removeHTMLTags(anmerkung) +"]]></Field>";
     }
     
     if(ausleitung != undefined && ausleitung != null) {
      batchCmd += "<Field Name='Ausleitung_x0020_geplant'>"+ ausleitung +"</Field>";
     }
     
     if(availableAt != undefined && availableAt != null) {
      batchCmd += "<Field Name='Available_x0020_at'>"+ availableAt +"</Field>";
     }
     
     if(beschreibung != undefined && beschreibung != null) {
      batchCmd += "<Field Name='Beschreibung'><![CDATA["+ removeHTMLTags(beschreibung) +"]]></Field>";
     }
     
     if(description != undefined && description != null) {
      batchCmd += "<Field Name='Description'><![CDATA["+ removeHTMLTags(description) +"]]></Field>";
     }
     
     if(emailempfaenger != undefined && emailempfaenger != null) {
      batchCmd += "<Field Name='Emailempf_x00e4_nger'>"+ emailempfaenger +"</Field>";
     }
     
     if(emailkommentar != undefined && emailkommentar != null) {
      batchCmd += "<Field Name='Emailkommentar'><![CDATA["+ removeHTMLTags(emailkommentar) +"]]></Field>";
     }
     
     if(erfasstAm != undefined && erfasstAm != null) {
      batchCmd += "<Field Name='Erfasst_x0020_am'>"+ erfasstAm +"</Field>";
     }
     
     if(legende != undefined && legende != null) {
      batchCmd += "<Field Name='Legende'>"+ legende +"</Field>";
     }
     
     if(offenerPunkt != undefined && offenerPunkt != null) {
      batchCmd += "<Field Name='Offener_x0020_Punkt_x0020_im_x00'><![CDATA["+ removeHTMLTags(offenerPunkt) +"]]></Field>";
     }
     
     if(prio != undefined && prio != null) {
      batchCmd += "<Field Name='PRIO'>"+ prio +"</Field>";
     }
     
     if(saPartNumber != undefined && saPartNumber != null) {
      batchCmd += "<Field Name='SA_x002F_Part_x0020_number'>"+ saPartNumber +"</Field>";
     }
     
     if(teileBezeichnung != undefined && teileBezeichnung != null) {
      batchCmd += "<Field Name='SA_x002F_Teilebezeichnung'>"+ teileBezeichnung +"</Field>"
     }
     
     if(status != undefined && status != null) {
      batchCmd += "<Field Name='_Status'>"+ status +"</Field>"
     }
     
     if(verantwortlicher != undefined && verantwortlicher != null) {
      batchCmd += "<Field Name='Verantwortlicher'>"+ verantwortlicher +"</Field>"
     }
     
     if(verfuegbarZu != undefined && verfuegbarZu != null) {
      batchCmd += "<Field Name='Verf_x00fc_gbar_x0020_zu'>"+ verfuegbarZu +"</Field>";
     }
     
     batchCmd += "</Method></Batch>";
     
//alert(batchCmd);
     
     try{
      $().SPServices({
       operation: "UpdateListItems",
       async: false,
       listName: list,
       updates: batchCmd,
       completefunc: function(xData, Status) {
        //alert(xData.responseXML.xml);
       }
      });
        }
      
       catch(e) {
     //alert(e);
       }
     });
   }
    });
    }
    catch(e) {
  //alert(e);
    }
   
    location.reload();
 });
}


/**
 * Remove HTML Tag <div></div> from Multiline text fields.
 */
function removeHTMLTags(htmlString){
 if (htmlString.indexOf("<div>") !=-1) {
        var mydiv = document.createElement("div");
        mydiv.innerHTML = htmlString;
 
        if (document.all) // IE
        {
            return mydiv.innerText;
        }  
        else // Mozilla does not work with innerText
        {
            return mydiv.textContent;
        }                          
 } else {
  return htmlString;
 }
}


Viewing all articles
Browse latest Browse all 2319

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>