Home › Forums › Classic DFFS › spjs utility / add item
- This topic has 2 replies, 2 voices, and was last updated 3 years, 9 months ago by DougMcCourt.
-
AuthorPosts
-
-
February 26, 2021 at 23:37 #32882
Hi Alexander and forum members!
Im looking to invoke a newform for a ‘child’ record – and am passing parms in a url i construct in the parent am looking for guidance on:
1: setting the child list item’s content type using custom js (based on parm1)
2: setting the child list items’s lookup value to the parent list – based on parm2)eg: xxxxx/NewForm.aspx?CType=T1&Parent=xxxxx
Ideally – the SPFieldLookup in the child list item should be xxxxx, and the ContentTypeChoice should be T1.var parm = “&”+location.search.substring(1);
var ary = parm.split(“&”);next line is trying to set the SPFieldLookup – doesnt work
data.Data_x0020_Req_x0020_ID = ary[1].substring(8);next line is trying to set the content type – doesnt work
data.ContentChoiceType = ary[2].substring(6)newItem = spjs.utility.addItem({“listName”:_spPageContextInfo.pageListId,”data”:data});
if(newItem.success){Many thanks
-
February 27, 2021 at 09:12 #32884
I’m not sure I understand how you want to create the child item – using the normal NewForm and pull values from the parameters in the URL or using code in the parent to create it.
I’ll start by showing how to do this programmatically from the parent item.
spjs.utility.addItem({ "listName":"Your_Child_List_GUID_Or_DisplayName", "data": { "Title": "New item created with code", "ContentTypeId": "0x0100", "Parent_Item_lookup_field": getFieldValue("ID") } });
Change the snippet and add your child list GUID or display name and your parent item lookup field name.
The content type “Item” has id “0x0100” and the “Task” has id “0x0108”. You find the id by looking at the URL when you try adding a new item in the child list using the specific content type.
Alexander
-
March 4, 2021 at 17:04 #32918
Hi Alexander – Thanksso much!
Heres what i ended up with 🙂
function NewChild(ChildType){
var data = {}, newItem, url;
var src=location.href.substring(0,location.href.indexOf(“&”));data.Title = ChildType + “: ” + getFieldValue(“ReqID”);
data.Data_x0020_Req_x0020_ID = getFieldValue(“ID”);
data.ContentTypeId = “0x0100E77C5DF82DE10E428F626F9C954B8E760096E526CBD027D145AA85C81E339A0ABA”;if(getFieldValue(“Req_x0020_Reg_x0020_Requirement”) === true ){
data.PII = true;
}if(getFieldValue(“Req_x0020_Reg_x0020_Requirement”) === true ){
data.Req_x0020_Requirement = true;
}if(getFieldValue(“Req_x0020__x002d__x0020_External”) === true){
data.Ext_x0020_Reporting = true;
}if(ChildType == “DG”){
data.ContentTypeId = “0x01007B6650D869D02E41B966BB31EBC45DB700C33EEB7BB1687946B0DC3B37AE3B0CCD”;
}newItem = spjs.utility.addItem({“listName”:”Request-Supplemental”,”data”:data});
if(newItem.success){
url = “http://sp-……my sharepoint site…./Lists/RequetSupplemental/EditForm.aspx?ID=”+newItem.id+”&”+src;
if(GetUrlKeyValue(“IsDlg”)===”1″){
url += “&IsDlg=1”;
}
location.href = url;
}else{
alert(newItem.errorText);
}
location.href=url;
}
-
-
AuthorPosts
- You must be logged in to reply to this topic.