How update selected child record from parent form when using vLookup?

Forums Classic DFFS How update selected child record from parent form when using vLookup?

Tagged: 

Viewing 1 reply thread
  • Author
    Posts
    • #19588
      Keith Hudson
      Participant

      I am using two related lists to manage the assignment of cubes to employees. The Request list gathers employee information when someone needs a new cube. The Cube list contains an inventory of all our cubes. The cube list contains a ParentID field that ties the cube record back to the appropriate Request record.

      I am using vLookup on the Request list edit form to be able to see what cubes are vacant. I am using vlookukp on the Cube list edit form to see fields from the Request list, ONCE the ParentID is saved in the Cube list record. This allows me to then to copy other information fields from the request list to the related Cube list record in order to create reports needed for cube moves.

      Right now, to assign someone a cube, I open the Request edit form, find a vacant cube by looking at the vlookup record of vacant cubes, then open the Cube record, add the ParentID from the Request record, save the Cube Record, then reopen the

      I would like to populate the ParentID (and if possible some other fields) on the Cube list for a selected child item shown on the parent edit form vlookup field.

      I’ve found this code in another forum discussion, and will test it to make sure I understand how it works:
      function callMeFromButton(){
      jQuery.each(spjs.vLookup.dataObj.vLookupTasks[spjs.dffs.data.thisItemID].items,function(id,vLookupListItem){
      spjs.utility.updateItem({
      “listName”:”THE_LIST_GUID_OF_CHILD_LIST”,
      “id”:id,
      “data”:{“Title”:”Updated title!”}
      });
      });
      }

      but it appears to rely on a button on the PARENT form to run the function, and then runs the function against ALL lines on the vlookup form.

      Is it possible to select one line from multiple lines shown on the vlookup form, and run a function to JUST update fields on that single child item? Perhaps by adding a button or link to each line of the vlookup form, or maybe add a text box to enter the line number before running the above code?

      • This topic was modified 6 years, 1 month ago by Keith Hudson. Reason: Edited topic title to match the question more closely
    • #19644
      Alexander Bautz
      Keymaster

      Hi,
      Sorry for the late reply. You should be able to use this snippet in Custom JS in the form where your vLookup column is rendered (to use in both DispForm and EditForm you must add the function to both forms):

      function updateChildItem(id,item){
          return "<input type='button' style='padding:2px 5px' onclick='doSetParentIdInChild(\""+id+"\");' value='Select this Cube'>";
      }
      
      function doSetParentIdInChild(id){
          var childListGuid = "{ccbbf922-f0af-481b-b2c0-b12ea24d224e}"; // Child list GUID
          var uRes = spjs.utility.updateItem({"listName":childListGuid,"id":id,"data":{"ParentID":spjs.dffs.data.thisItemID}});
          if(uRes.success){
              spjs.dffs.alert({"title":"Cube selected","msg":"Add something here, or comment out this alert."});
          }else{
              alert(uRes.errorText);
          }
      }

      Then add the ID column to your vLookup config viewFields – name it “Select Cube” and add this in the “Special configuration”:

      {"function":"updateChildItem"}

      If you don’t want to show the button in DispForm you must add this function there:

      function updateChildItem(id,item){
          return "Enter EditForm to select Cube";
      }

      You must change “childListGuid” to match your child list GUID or DisplayName.

      Let me know how this works out.

      Alexander

      • This reply was modified 6 years, 1 month ago by Alexander Bautz. Reason: Added info about childListGuid
Viewing 1 reply thread
  • You must be logged in to reply to this topic.