Home › Forums › vLooup for SharePoint › Create from Existing item in vLookup
- This topic has 4 replies, 3 voices, and was last updated 8 years, 4 months ago by avala.
-
AuthorPosts
-
-
October 9, 2015 at 16:24 #8688
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
-
October 14, 2015 at 17:47 #8779
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
-
August 5, 2016 at 14:22 #12694
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?
-
August 8, 2016 at 22:56 #12729
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-
August 9, 2016 at 15:29 #12753
Perfect,it works flawlessly! Thank you so much!
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.