Update data in list B from list A on save

Home Forums Classic DFFS Update data in list B from list A on save

Viewing 7 reply threads
  • Author
    Posts
    • #27191
      Jon Whisman
      Participant

        I have 2 lists working together in a form via some DFFS cascades and vLookups. I also have a worflow that is SUPPOSED to be setting fields in list B once list A has certain updates made.

        Our SharePoint infrastructure is not the best at the moment, so I am looking for alternatives to updating list B’s data from the list A form when the user saves list list A form.

        The binding data between the 2 would be IDs and various data brought in from list B that the user selects in the list A form.

        EG:

        List A is a “Protege” list.
        List B is a “Mentor” list.

        In List A (Protege), user selects Mentor data (List B) to be paired via series of cascade drop downs in the form.

        On Save of list A, I want to UPDATE the selected mentor (list B) that the mentor has been paired with protege so that both are taken out of the pool for future selections. This is what the workflow is SUPPOSED to be doing, but fails quite a lot.

        Is there an spjs function for doing updates to data between lists based on data I select other than ID betweeen the lists? EG: Bind would be where mentorID = protegeID.

      • #27197
        Alexander Bautz
        Keymaster

          You can use some custom js to read or update values from another list. I’m not 100% sure I understand what you mean though. If the person filling in list A uses a cascading dropdown and selects a Mentor from list B – how should the data in list B be modified? – remove the person from the Mentor field, flag it with a value in a field (like “selected = yes) or delete the item?

          Because the cascading dropdown does not retrieve the id of the list item, you would have to use the selected values in a query to get the item. If you can sow me some screenshots of your list a and b (please mask any sensitive data) I can create a code snippet to get you started.

          Please note: using custom js in DFFS means any updates in datasheet view will NOT trigger the code.

          Alexander

        • #27221
          Jon Whisman
          Participant

            Hi Alexander,

            To answer your question, what I’m after is the below.

            The person filling in list A uses the a cascading dropdown and selects a Mentor from list B. On Save (I’ll use the preSave function), the data in list B should be modified to update fields in list B as below:

            paired = yes
            set protegeID (ID from list A) into protegeID into list B.

            This way, I can use vLookup in a list view of list A to pull back data from list B of who list A people have been paired with from list B based on ID.

            Hope this makes sense. The workflow does the above at the moment, but randomly fails.

          • #27240
            Alexander Bautz
            Keymaster

              Sorry for the late reply.
              Because the cascading dropdown does not pull back the ID of the list item we need to build a query to find the correct list item in list b to update the values.

              Will the Mentor field in list b have unique values, or is it the combination of cascading dropdowns (level1 > level2 > mentor) that is unique? – if so, can you show me the config for the cascading dropdown so I can replicate it to create the code example?

              Alexander

            • #27383
              Jon Whisman
              Participant

                Sorry for my late reply.

                The cascading dropdown actually does pull back an ID (‘mentorID’) from the lookup list. I place this into a ‘mentorID’ field within the current item at the end of the cascade in the form. The ‘mentorID’ in the lookup list is set upon item creation via workflow from the lookup list ID field.

                With that, all I’m after is creating a new function I can do via dffs_PreSaveAction in the current item that will update certain fields in list B, doing a match against the ‘mentorID’ in the current item to the ‘mentorID’ in the lookup list.

              • #27405
                Alexander Bautz
                Keymaster

                  Try it like this:

                  function dffs_PreSaveAction() {
                      var res = spjs.utility.updateItem({
                          "listName": "The display name or GUID of list b",
                          "id": getFieldValue("mentorID"),
                          "data": {
                              "paired": "1", // Boolean Yes/No field
                              "protegeID": spjs.dffs.data.thisItemID
                          }
                      });
                  
                      if (res.success) {
                          // Updated successfully
                      } else {
                          alert(res.errorText);
                          return false; // < stops the save process
                      }
                  }

                  Alexander

                • #28252
                  Jon Whisman
                  Participant

                    The above is working great for the initial solution, but I have a new need:

                    Update the folder name name in a document library base don the vLookup item in the current item to the _vLookupParentID in the child item.

                    I’m having difficulty re-naming the folder name (INT = FileLeafRef), but also understanding how to specify a different id in the child list to target.

                    I want to target the vlookup column in the child list, matching to the vlookup column in the parent list. How to write this in the spjs.utility.updateItem?

                    
                    
                        var res = spjs.utility.updateItem({
                            "listName": "my_document_library_child_list",
                            "id": getFieldValue("_vLookupID"), //vLookup ID in parent list
                            "data": {
                                "FileLeafRef": "NEW_FOLDER_NAME_TEST", // The Folder Name in the child library
                            }
                        });
                    
                        if (res.success) {
                            // Updated successfully
                        } else {
                            alert(res.errorText);
                            return false; // stops the save process
                        }
                    }
                    • This reply was modified 4 years, 10 months ago by Jon Whisman.
                  • #28273
                    Alexander Bautz
                    Keymaster

                      Hi,
                      Renaming a folder cannot be done with spjs.utility.updateItem, but you can use JSOM as shown here: https://social.msdn.microsoft.com/Forums/office/en-US/1d9ba422-35d6-4904-a9a8-c95a6667ec26/change-document-library-folder-name-from-client-javascript-jsom-or-rest?forum=sharepointdevelopment

                      To do this you must have the ID of the folder, and this can be fetched using the _vLookupID like this:

                      var res = spjs.utility.queryItems({
                          "listName": "{ab6a0e84-43e0-4acd-a76a-3d96e9a70933}",
                          "query": "<Where><Eq><FieldRef Name='FileLeafRef' /><Value Type='Text'>"+getFieldValue("_vLookupID")+"</Value></Eq></Where>",
                          "viewFields": ["ID"]
                      });
                      if(res.count > 0){
                        var folderId = res.items[0].ID;
                        // Run rename code here
                      }

                      Alexander

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