Child form

Home Forums General discussion Child form

Viewing 29 reply threads
  • Author
    Posts
    • #31109
      Leonid
      Participant

        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!

      • #31113
        Alexander Bautz
        Keymaster

          This is more or less what the vLookup plugin is used for: https://spjsblog.com/vlookup-for-sharepoint/

          Alexander

        • #31143
          Leonid
          Participant

            Thx Alex! Would it allow use rules for the fields in the chcild list?

          • #31145
            Leonid
            Participant

              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

            • #31147
              Leonid
              Participant

                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.

              • #31149
                Leonid
                Participant

                  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

                • #31151
                  Alexander Bautz
                  Keymaster

                    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

                    • #31550
                      Leonid
                      Participant

                        Just tested hiding the vlookup button. Brilliant!

                    • #31152
                      Leonid
                      Participant

                        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

                      • #31157
                        Alexander Bautz
                        Keymaster

                          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

                        • #31195
                          Leonid
                          Participant

                            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
                          • #31201
                            Alexander Bautz
                            Keymaster

                              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

                            • #31204
                              Leonid
                              Participant

                                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:
                              • #31207
                                Alexander Bautz
                                Keymaster

                                  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

                                • #31217
                                  Leonid
                                  Participant

                                    Alex,
                                    The button visibility is driven only by the Rule on the dropdown.

                                  • #31238
                                    Alexander Bautz
                                    Keymaster

                                      Not sure I follow, please show me some screenshots of your current code and corresponding rules.

                                      Alexander

                                    • #31266
                                      Leonid
                                      Participant

                                        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:
                                      • #31296
                                        Alexander Bautz
                                        Keymaster

                                          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

                                        • #31303
                                          Leonid
                                          Participant

                                            Got it. I will set the field visible and hide it on form loaded instead. Hope that will work

                                          • #31305
                                            Leonid
                                            Participant

                                              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?

                                            • #31307
                                              Alexander Bautz
                                              Keymaster

                                                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

                                              • #31308
                                                Alexander Bautz
                                                Keymaster

                                                  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

                                                • #31311
                                                  Leonid
                                                  Participant

                                                    Alex, Im emailing snapshots and vLookup config to your gmail.
                                                    Im running 4.4.4.23 DFFS Loader with 1.1.19 Lookup

                                                  • #31329
                                                    Leonid
                                                    Participant

                                                      Any luck in pointing me to right direction?

                                                    • #31331
                                                      Alexander Bautz
                                                      Keymaster

                                                        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

                                                      • #31343
                                                        Leonid
                                                        Participant

                                                          Alex,
                                                          The issue is with vlookup: fields not pre-filling in the Edit form whereas they prefill in the New form, same configuration

                                                          • This reply was modified 4 years, 3 months ago by Leonid.
                                                        • #31350
                                                          Alexander Bautz
                                                          Keymaster

                                                            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

                                                          • #31369
                                                            Leonid
                                                            Participant

                                                              I posted 2 replies and none made it to this thread

                                                              • #31385
                                                                Alexander Bautz
                                                                Keymaster

                                                                  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

                                                              • #31371
                                                                Leonid
                                                                Participant

                                                                  I redid the whole thing with new lists and sofar prefill is working

                                                                • #31454
                                                                  Leonid
                                                                  Participant

                                                                    Alex,
                                                                    For the snippet

                                                                    
                                                                    
                                                                    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);
                                                                        }
                                                                    }

                                                                    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?

                                                                  • #31456
                                                                    Alexander Bautz
                                                                    Keymaster

                                                                      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

                                                                  Viewing 29 reply threads
                                                                  • You must be logged in to reply to this topic.