Home › Forums › vLooup for SharePoint › vLookup child value back to parent
- This topic has 5 replies, 2 voices, and was last updated 7 years, 10 months ago by Alexander Bautz.
-
AuthorPosts
-
-
February 13, 2017 at 22:24 #15601
I’m trying to figure out if the below is possible and if so the best way to accomplish it.
I have a parent list and want to create a child questionnaire. I want to limit the responses to 1. So within DFFS parent list I want the user to be able to create only 1 child item. In addition I want to bring back the value of one field in the child to the parent so that rules can be run. Or be able to query the child item to execute a rule after I save the child item. I hope this makes sense.
- This topic was modified 7 years, 10 months ago by Kasey.
-
February 13, 2017 at 22:44 #15604
I got some help and was able to figure out how to get the value in the child item and can add it in a function in custom js. Is there something I can use to trigger the function on saving the child item? And is there a good way to limit the child items to just one?
-
February 13, 2017 at 23:10 #15612
Here is the function I plan on implementing. I would only allow add/edit on New or Edit. Is there a trigger I can use to know when to call the function after a child vlookup has been added or edited? And is there a way to limit to just one child item. Sorry for all the posts.
function setParentFromChild(vLookup,vLookupChildField,parentField){
var parentID = getFieldValue(“ID”);
var childValue = for (childItem in spjs.vLookup.dataObj[vLookup][parentID].items) {spjs.vLookup.dataObj[vLookup][parentID].items[childItem][vLookupChildField]};
setFieldValue(parentField,childValue);
}- This reply was modified 7 years, 10 months ago by Kasey.
-
February 13, 2017 at 23:51 #15615
Updated Function…
function setParentFromChild(vLookup,vLookupChildField,parentField){
var parentID = getFieldValue(“ID”);
var childValues = [];
for (childItem in spjs.vLookup.dataObj[vLookup][parentID].items) {
spjs.vLookup.dataObj[vLookup][parentID].items[childItem][vLookupChildField]
childValues.push(childItem);};setFieldValue(parentField,childValues[0]);
} -
February 14, 2017 at 00:51 #15617
Final update to function. I thought I tested it fully but didn’t.
function setParentFromChild(vLookup,vLookupChildField,parentField){
var parentID = getFieldValue(“ID”);
var childValues = [];
for (childItem in spjs.vLookup.dataObj[vLookup][parentID].items) {
childValues.push(spjs.vLookup.dataObj[vLookup][parentID].items[childItem][vLookupChildField]);
};
setFieldValue(parentField,childValues[0]);
} -
February 16, 2017 at 21:17 #15676
Sorry for the delay, I’ve been busy with catching up on a few bugs and older questions in the forum and in my mailbox.
Here is an example of a custom function to open a child item where you can control the callback:
function openCustomDialog(){ var url = "your_site/Lists/DFFS_TestList/NewForm.aspx?parentListGuid="+_spPageContextInfo.pageListId+"&parentForm="+location.pathname+"&parentItemId="+spjs.dffs.data.thisItemID+"&baseUrl="+_spPageContextInfo.webServerRelativeUrl+"&getFromParent=_vLookupID|_vLookupParentID|false~Title|Title|false" SP.UI.ModalDialog.showModalDialog( { "url":url, "dialogReturnValueCallback":customCallbackFunc } ); } function customCallbackFunc(ok){ if(ok){ alert("Clicked OK"); }else{ alert("Clicked Cancel"); } }
Call the function “openCustomDialog” from a button to open the dialog, and modify the function “customCallbackFunc” to catch the callback.
I think maybe the check to see if the user has already responded could be put in the child NewForm like this:
var res = spjs.utility.queryItems({"listName":_spPageContextInfo.pageListId,"query":"<Where><Eq><FieldRef Name='Author' /><Value Type='Integer'><UserID /></Value></Eq></Where>","viewFields":["ID"],"rowLimit":1}); if(res.count > 0){ alert("Sorry, you cannot take the survey more than one time."); $("input[id$='diidIOGoBack']:last").trigger("click"); }
Hope this gets you on the right track.
Best regards,
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.