Create from Existing item in vLookup

Home Forums vLooup for SharePoint Create from Existing item in vLookup

Tagged: ,

Viewing 3 reply threads
  • Author
    Posts
    • #8688
      Robert Sawyer
      Participant

        Hi Alexandar,

        First of all, you have a great toolkit!
        I’m excited to investigate your latest feature to allow the creation of an item in the vLookup on the new form!

        My question, do you have the ability to create a new item in the vLookup based upon an item that already listed within the vLookup? i.e Allow the user to select an existing item in the vLookup and create a new item where the columns are automactically copied to the new item. Or, open a dialog box of the items within vLookup and allow the selection of an item from which the columns are copied to a new item?

        I hope this makes sense, please message me if you require more clarity or information?

        Regards

        Rob

      • #8779
        Alexander Bautz
        Keymaster

          Hi,
          Sorry for the delay in answering. I currently don’t have a ready solution for copying a list item, but basically what you need to do is to use a query to find the values you want to copy, and then add a new item with the data.

          Here is a basic example:

          function copyListItem(itemToCopy){
          	var oRes, viewFields = ["Title","AssignedTo"], data = {};
          	oRes = spjs.utility.getItemByID({"listName":"Tasks","id":itemToCopy,"viewFields":viewFields});
          	if(oRes !== null){
          		$.each(oRes,function(key,val){
          			if(key !== "ID"){
          				data[key] = val;
          			}	
          		})
          		nRes = spjs.utility.addItem({"listName":"Tasks","data":data});
          		if(!nRes.success){
          			alert("ERROR:\n"+nRes.errorText);
          		}else{
          			alert("A new item with ID "+nRes.id+" was created.");
          		}
          	}else{
          		alert("No item found");
          	}
          }

          You must know the ID of the item you want to clone – and call the function like this:

          copyListItem(123);

          Where 123 is the ID of the list item you want to clone.

          In this function you must insert the FieldInternalNames in the ViewFields array, and change the list display name from “Tasks” to you lists display name or GUID.

          Let me know how this works out.

          Alexander

        • #12694
          avala
          Participant

            Did you get this to work? Can you include an example of your configuration and how you have the user selecting which vLookup item they want to copy?

          • #12729
            Alexander Bautz
            Keymaster

              Look at this example: https://spjsblog.com/forums/topic/conditional-format-of-column/#post-9573

              Use the same method, but change the function used in the special configuration to “init_copyItems”

              function init_copyItems(a,b){
              	var id = b.get_item("ID");
              	a = "<span style='cursor:pointer;' onclick='copyListItem(\""+id+"\")'>Copy item</span>";
              	return a;
              }

              If the vLookup item should appear in the table you must call the refresh function like this after the copy function has finished (in copyListItem function):

              spjs.vLookup._init("vLookup_NameOfYourComumn",false,true);

              Hope this helps,
              Alexander

              • #12753
                avala
                Participant

                  Perfect,it works flawlessly! Thank you so much!

            Viewing 3 reply threads
            • You must be logged in to reply to this topic.