dffs vlookup,Precancel events,control of cancel list item

Forums General discussion dffs vlookup,Precancel events,control of cancel list item

Viewing 9 reply threads
  • Author
    Posts
    • #15963
      Navya Marla
      Participant

      Hi,

      i have a DFFS configured for the Newform which has some vlookup functionlaity in it.the functionlaity was working great….
      when the user clicked on cancel button in the parent New form the child items are still available in the child list as they are already saved in the child list.
      How can we delete those records in the child list if the parent item is not saved?
      can we write any client side code before the normal cancel functionality like PRESAVE for the save button?

      Thanks,
      Navya

    • #16000
      Alexander Bautz
      Keymaster

      Hi,
      There is no built in functionality in DFFS to handle this, but if this is a problem you need to address it could be done with some custom code in “Custom JS”:

      // Keep track of the item being saved or not
      var isSaved = false;
      window.onbeforeunload = function() {
          if(!isSaved){
              var items = [];
              $.each(spjs.vLookup.dataObj.vLookupTasks[getFieldValue("_vLookupID")].items,function(id,item){
                  if(item.hasOwnProperty("ID")){
                      items.push(id);
                  }
              });
              if(items.length > 0){
                  spjs.utility.deleteItem({"listName":"ChildListTitleOrGUID","id":items});
              }
          }
      };
      
      function dffs_PreSaveAction(){
          isSaved = true;
          return true;
      }

      Please change “vLookupTasks” to match your vLookup field name and “ChildListTitleOrGUID” to match the child lists display name or GUID.

      Hope this helps,
      Alexander

    • #25717
      Tony
      Participant

      Hi,

      I implemented the above script in my parent list but it did not work. Attached is my complete function.
      dRes is giving the error msg: Access denied. You do not have permission to perform this action or access this resource
      Knowing that the current user has full permissions on site and can manually delete the child document from the library.

      Attachments:
    • #25724
      Alexander Bautz
      Keymaster

      Hi,
      When trying to delete a document you must also supply the full document url – look at this example: https://spjsblog.com/forums/topic/delete-button-on-child-item-with-refresh-for-document-library/#post-12235

      Alexander

    • #25726
      Tony
      Participant

      Hi again,

      In my example I have an array of item ids, will it work if I added docurls array to delete all child documents similat to deleting all childs in custom lists??

    • #25730
      Alexander Bautz
      Keymaster

      I don’t think you can, try looping tough each item and delete it one by one.

      Alexander

    • #25734
      Tony
      Participant

      Hi Again,
      I tried to get the URL using the below:

      
      
      $.each(spjs.vLookup.dataObj["vLookupLivret"][getFieldValue("_vLookupID")].items,function(id,item){
                  //alert("each");   
                  if(item.hasOwnProperty("ID")){
                      URL = item.get_item('FileDirRef');// + "/"+ item.get_item('FileLeafRef');
                      URLs.push(URL);
                      items.push(id);
                      //alert(item.get_item('FileDirRef'));
                      
                  }
              });

      but i am getting get_item is not a supported method.

    • #25745
      Alexander Bautz
      Keymaster

      If you use it in NewForm your first line is correct like this:

      $.each(spjs.vLookup.dataObj[“vLookupLivret”][getFieldValue(“_vLookupID”)].items,function(id,item){

      but if you do this in DispForm or EditForm you must change it like this:

      $.each(spjs.vLookup.dataObj[“vLookupLivret”][spjs.dffs.data.thisItemID].items,function(id,item){

      Alexander

    • #25747
      Tony
      Participant

      Thank you for your reply

      Yes i am using each syntax correctly in each form. And it is entering the each loop with the id pushed correctly. But once trying to use get_item, I am getting the error.

      Tony

    • #25759
      Alexander Bautz
      Keymaster

      Try adding this console.log here (hit F12 to bring up the dev console and select Console) – then reload the page:

      console.log(item);
      URL = item.get_item('FileDirRef');

      What does the console show?

      Alexander

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