Home › Forums › General discussion › Child form
- This topic has 31 replies, 2 voices, and was last updated 4 years, 3 months ago by Leonid.
-
AuthorPosts
-
-
August 10, 2020 at 15:15 #31109
Hi,
Wondering of recommendations oh how open a secondary (child) form from a main form and return back to the original one after the secondary is submitted. Thoughts welcome! -
August 10, 2020 at 18:17 #31113
This is more or less what the vLookup plugin is used for: https://spjsblog.com/vlookup-for-sharepoint/
Alexander
-
August 11, 2020 at 15:12 #31143
Thx Alex! Would it allow use rules for the fields in the chcild list?
-
August 11, 2020 at 18:13 #31145
Looks like I already know the answer to previous question – its yes. Right now Im puzzled to pass ID of a newly created item in a child list to a field in the parent list in a New form
-
August 11, 2020 at 18:53 #31147
Here is the part Im not getting. The sample suggests autopopulating parentId in the Child list from parent’s list ID. But that ID doesnt exist in a New form, only in Edit and View forms. My approach is to pass ID from the Child list (after item is created there) to a field in the New form. That doesnt work.
-
August 11, 2020 at 19:44 #31149
Continuing with mono- discussion. It appears that ID is not item ID but randomly generated unique ID prior to item creation, and it works. I still need to save child item ID in a parent list because parent list has multiple association with the same child list and reverse ralationship is much simpler.
The other question, whats the best way to make Add Child Record button conditional? E.g. I want to show it only when there is no records in the child list matching query
-
August 11, 2020 at 21:20 #31151
Hi,
As you already have figured out, the _vLookupID column is auto-generated and used to link the two items together.Also, you cannot get the ID directly from NewForm. What you can try in the Parent form, is to add this code snippet to pick up the last item added and write the ID to a field.
function vlookupChildAddedCallback(){ var res = spjs.utility.queryItems({ "listName": "DISPLAY_NAME_OF_CHILD_LIST", "query": "<Where><Eq><FieldRef Name='_vLookupParentID' /><Value Type='Text'>"+getFieldValue("_vLookupID")+"</Value></Eq></Where><OrderBy><FieldRef Name='ID' Ascending='FALSE' /></OrderBy>", "rowLimit": 1, "viewFields": ["ID"] }); if(res.count > 0){ var newItemId = res.items[0].ID; setFieldValue("THE_FIELD_YOU_WANT_TO_SET", newItemId); } }
Replace DISPLAY_NAME_OF_CHILD_LIST and THE_FIELD_YOU_WANT_TO_SET with the correct ones.
To dynamically hide the button if there is items already added you can add this custom js:
function vLookupIsLoadedCallback(fin) { if (fin === "NAME_OF_YOUR_VLOOKUP_FIELD") { if(spjs.vLookup.dataObj[fin][spjs.dffs.data.thisItemID].count > 0){ jQuery("#dffs_" + fin).find("#newItemWrap_" + fin).hide(); } } }
Replace NAME_OF_YOUR_VLOOKUP_FIELD with the correct field name.
Alexander
-
September 11, 2020 at 15:51 #31550
Just tested hiding the vlookup button. Brilliant!
-
-
August 12, 2020 at 14:10 #31152
Thanks Alex, I will try that! What is the best event to add the code in New form to ensure it fires right after the Child item created?
Followup questions:
I need multiple associations: whats the naming rule for _vLookupID? e.g. _vLookupID1, _vLookupID2, etc.Do I understand correctly that if I use regular item IDs those wont work in Edit form to show proper relationship between Parent and Child. Thus OOB lookup wont work
-
August 12, 2020 at 20:16 #31157
Hi,
This function does not have the field name as an argument, but we have the field name in a variable and can use it like this:function vlookupChildAddedCallback() { switch (spjs.vLookup.data.refreshThisField) { case "vLookup_field1": // Do something for vLookup_field1 break; case "vLookup_field2": // Do something for vLookup_field2 break; } }
I’m not sure I understand your last sentence – can you clarify?
Alexander
-
August 13, 2020 at 17:47 #31195
Thanks Alex! To clarify vlookupChildAddedCallback(): Im using folders with vLookup. CAML query should have a recursive scope to go through the folders (?). How this can be accomplished with
spjs.utility.queryItems
-
August 13, 2020 at 22:15 #31201
Add “scope” like this:
var res = spjs.utility.queryItems({ "listName": "DISPLAY_NAME_OF_CHILD_LIST", "query": "<Where><Eq><FieldRef Name='_vLookupParentID' /><Value Type='Text'>" + getFieldValue("_vLookupID") + "</Value></Eq></Where><OrderBy><FieldRef Name='ID' Ascending='FALSE' /></OrderBy>", "rowLimit": 1, "viewFields": ["ID"], "scope":"RecursiveAll" });
Alexander
-
August 14, 2020 at 22:10 #31204
That worked like a charm!
Im facing sort of rendering issue with multiple vLookups. Sometimes only 1st button shows up. 2nd vlookup button will show if I click the one shown and then close the dialogue
Attachments:
-
August 15, 2020 at 07:45 #31207
Not sure what could cause this – do you have any custom css or js to hide this button? – if not, try hitting f12 to bring up the developer console and see if you have any errors there.
Alexander
-
August 17, 2020 at 21:32 #31217
Alex,
The button visibility is driven only by the Rule on the dropdown. -
August 18, 2020 at 15:42 #31238
Not sure I follow, please show me some screenshots of your current code and corresponding rules.
Alexander
-
August 19, 2020 at 20:35 #31266
The only function related to vLookup is:
`function vlookupChildAddedCallback(){
var res = spjs.utility.queryItems({
“listName”: “LCR Answers”,
“query”: “<Where><And><Eq><FieldRef Name=’_vLookupParentID’ /><Value Type=’Text’>” + getFieldValue(“_vLookupID”) +
“</Value></Eq><Contains><FieldRef Name=’FileRef’ /><Value Type=’Text’>” + LCR_ID +
“</Value></Contains></And></Where><OrderBy><FieldRef Name=’ID’ Ascending=’FALSE’ /></OrderBy>”,
“rowLimit”: 1,
“viewFields”: [‘ID’, ‘Title’, ‘FileRef’],
“scope”:”RecursiveAll”
});
if(res.count > 0){
//debugger;
var id = res.items[0].ID;
var title = res.items[0].Title;
setFieldValue(title.replace(” “, “”) + “ID”, id);
}
}and the rule is attached
- This reply was modified 4 years, 4 months ago by Leonid.
Attachments:
-
August 20, 2020 at 21:47 #31296
Ah, I think this is a bug related to the field being hidden initially when the tab is rendered. The vLookup field is only initiated if the field is visible and it looks like it does not initiate correctly when being made visible by a rule. I’ll look into this and see if there is something I can do to fix it in the next release. In the meantime you might consider just leaving the field visible.
Alexander
-
August 21, 2020 at 13:33 #31303
Got it. I will set the field visible and hide it on form loaded instead. Hope that will work
-
August 21, 2020 at 13:44 #31305
Alex, the other question came up. I copied vLookup settings from New to Edit form.
Prefill values in child works fine in the New form, but doesnt in the Edit form. Is there some settings that should be adjusted? -
August 22, 2020 at 08:25 #31307
If you create a new child item from the parent items EditForm it should still prefill values in the child item NewForm. Can you show me a screenshot of your config and also note what field types you are trying to set.
Alexander
-
August 23, 2020 at 08:26 #31308
Hi Leonid,
I tried to recreate the problem with the vLookup field not rendering when you had it hidden in a rule initially, but could not get the same result as you.As soon as the choice is selected (and the rule is evaluated to true) the vLookup field shows as it should.
Which version of DFFS are you running (hover over the Enhanced with DFFS below the form and click the License and version information link)?
Alexander
-
August 24, 2020 at 14:04 #31311
Alex, Im emailing snapshots and vLookup config to your gmail.
Im running 4.4.4.23 DFFS Loader with 1.1.19 Lookup -
August 25, 2020 at 15:07 #31329
Any luck in pointing me to right direction?
-
August 25, 2020 at 16:19 #31331
Sorry for the late reply. I looked at the screenshots and cannot see anything that could cause he button to now show.
I cannot remember to have fixed this explicitly, but if you are able to update to the latest version and test it it would help me trying to sort out the problem.
Alexander
-
August 26, 2020 at 12:54 #31343
-
August 26, 2020 at 18:48 #31350
Ah, sorry about that. Unfortunately I don’t see anything that could cause the form to not prefill when adding a child item from EditForm. Do you see any error messages if you open the developer console (hit f12 > console)?
Also, is there any difference if you test it in another browser?
Alexander
-
August 27, 2020 at 16:01 #31369
I posted 2 replies and none made it to this thread
-
August 27, 2020 at 20:13 #31385
The two comments were interpreted as spam and filtered out. I deleted them now that you got it working.
PS: I looked at the errors and it didn’t really tell me anything other that that there was an error in the spellcheck in a rich text field.
Alexander
-
-
August 27, 2020 at 16:13 #31371
I redid the whole thing with new lists and sofar prefill is working
-
September 1, 2020 at 18:08 #31454
Alex,
For the snippetfunction vlookupChildAddedCallback(){ var res = spjs.utility.queryItems({ "listName": "DISPLAY_NAME_OF_CHILD_LIST", "query": "<Where><Eq><FieldRef Name='_vLookupParentID' /><Value Type='Text'>"+getFieldValue("_vLookupID")+"</Value></Eq></Where><OrderBy><FieldRef Name='ID' Ascending='FALSE' /></OrderBy>", "rowLimit": 1, "viewFields": ["ID"] }); if(res.count > 0){ var newItemId = res.items[0].ID; setFieldValue("THE_FIELD_YOU_WANT_TO_SET", newItemId); } }
Seems setFieldValue works only if SAVE button clicked on Edit form of the Parent item. Any way to set the field value w/o forcing user click Save?
-
September 1, 2020 at 20:39 #31456
Sorry, but the only way to get the values saved in the parent is by manually saving it.
It is possible to write back and save it directly from the child item, but the you would get a save conflict when returning to the parent editform and trying to manually save it (because updating with code from the child makes a new version).
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.