Home › Forums › General discussion › Adding a new item with a custom button
- This topic has 2 replies, 2 voices, and was last updated 8 years, 5 months ago by Penny Kingston.
-
AuthorPosts
-
-
July 19, 2016 at 20:26 #12423
Hi Alex, I am using a custom button to add a new item (eventually adding multiple items with the same data). I am defining the fields that I would like to transfer to the new item(s). However, there is one field that causes the “spjs.utility.addItem” function to fail. It is a lookup field. There are two other lookup fields that transfer with no issues. I am stumped. Any thoughts? My code is below.
The field that fails is “NewColumn1”. SkillID and LookupEffort are also lookup fields but work fine. Thanks!function copy(){spjs.dffs.data.requiredFields.push("Title"); var ok = spjs.dffs.check_Mandatory(["Title"]), data = {}, newItem, d = getFieldValue("Start").split("/"), f = getFieldValue("End").split("/"), g = getFieldValue("Requested").split("/"); if(ok){ data.Start=d[2]+"-"+d[0]+"-"+d[1]; data.End=f[2]+"-"+f[0]+"-"+f[1]; data.Requested=g[2]+"-"+g[0]+"-"+g[1]; data.Title=getFieldValue("Title"); data.Lead=getFieldValue("Lead"); data.LookupEffort=getFieldValue("LookupEffort"); data.SkillID=getFieldValue("SkillID"); data.NewColumn1 = getFieldValue("NewColumn1"); newItem = spjs.utility.addItem{"listName":_spPageContextInfo.pageListId,"data":data}); }}
-
July 20, 2016 at 09:01 #12441
Hi,
I guess the NewColumn1 is a multi select? – in any case, you should use something like this to get the lookup value in the proper format for adding new items with code:function getLookupValue(fin){ var b = [], s if($("#dffs_"+fin).find("select").length === 1){ s = $("#dffs_"+fin).find("select").find("option:selected"); if(s.val() !== "0"){ b.push(s.val()+";#"+s.text()); } }else{ $("#dffs_"+fin).find("select:last").find("option").each(function(i,o){ b.push($(o).val()+";#"+$(o).text()); }); } return b.join(";#"); }
Use this function like this:
data.NewColumn1 = getLookupValue("NewColumn1");
Alexander
-
July 20, 2016 at 16:50 #12443
That worked perfectly! I am not sure why the other lookup fields appeared to work originally but just to be safe I used this function on all lookup fields.
Thanks! Penny
-
-
AuthorPosts
- You must be logged in to reply to this topic.