Count files in child folder when using the vLookup Add new Folder / doc library

Forums vLooup for SharePoint Count files in child folder when using the vLookup Add new Folder / doc library

Viewing 5 reply threads
  • Author
    Posts
    • #28209
      Jon Whisman
      Participant

      Is there a way when using the vLookup Add new folder functionality that we can accurately tell if the user has uploaded a document or not?

      Scenario: we have a column in the parent list (this item). The column name is “Attachments?”

      When the user creates a folder, we update this column during the vLookup refresh to be a “Yes”.

      Problem: sometimes the user creates the folder only and forgets to upload the actual document, or uploads it later.

      The need: Only update our “Attachments?” column in the current item when there is a folder AND when that folder contains at least 1 file.

      Thoughts?

    • #28220
      Alexander Bautz
      Keymaster

      You can use the spjs.vLookup.dataObj to check that the attachment has been added. Look in the user manual for some details: https://spjsblog.com/vlookup-for-sharepoint/vlookup-user-manual/

      If you search the forum form spjs.vLookup.dataObj you will find some threads about it also.

      Alexander

    • #28265
      Jon Whisman
      Participant

      Thanks – I’ve gotten the below, and in the attached file you’ll see the results of the console output. I am trying to get the ‘count’ into a variable so that I can it for other logic. What syntax do I use in the vLookup dataObj or the spjs.dffs.data to get the count from the result in the attached image?

      The function I have so far:

      
      
      function testDataLog(){
          window.console  &&  console.log(spjs.vLookup.dataObj['vLookupAttachments'][spjs.dffs.data.thisItemID]);
      }
      Attachments:
    • #28282
      Alexander Bautz
      Keymaster

      That would be like this:

      spjs.vLookup.dataObj['vLookupAttachments'][spjs.dffs.data.thisItemID].count;

      I’m however not 100% sure this will work – it requires that the folder is expanded to be counted. If you can show me how your query for this vLookup looks like I might be able to write a separate query you can use to do the counting.

      Alexander

    • #28284
      Jon Whisman
      Participant

      The vLookup query is below. I set the current item vLookupID to a field “actionPlanID” in the child list, which is the document library.

      <Where><Or><Eq><FieldRef Name='actionPlanDocID'/><Value Type='Text'>[currentItem:_vLookupID]</Value></Eq><Eq><FieldRef Name='actionPlanID'/><Value Type='Text'>[currentItem:ID]</Value></Eq></Or></Where>
    • #28288
      Jon Whisman
      Participant

      Here is what I have come up with – working beautifully.

      
      
      function checkForAttachments() {
          //check for a folder first
          var vLookupID = getFieldValue("_vLookupID","disp"); //vLookup ID from THIS item
          var res = spjs.utility.queryItems({
              "listName": "{LIST_GUID}", 
              "query": "<Where><Eq><FieldRef Name='VLOOKUP_INTERNAL_FIELD_NAME_FROM_CHILD_LIST' /><Value Type='Text'>"+vLookupID +"</Value></Eq></Where>",
              "viewFields": ["ID"]
          });
      
          if(res.count > 0){
              var folderID = res.items[0].ID; 
              window.console  &&  console.log("folderID = " + folderID);
              //query for child items in the folder
              var res = spjs.utility.queryItems({
                  "listName": "{LIST_GUID}",
                  "query": "<Where><Eq><FieldRef Name='VLOOKUP_INTERNAL_FIELD_NAME_FROM_CHILD_LIST'/><Value Type='Text'>"+vLookupID+"</Value></Eq></Where>",
                  "viewFields": ["ItemChildCount"]
              });
              //window.console  &&  console.log(res);
              var IDAttachmentCount = res.items[0].ItemChildCount;
              window.console  &&  console.log("IDAttachmentCount = " + IDAttachmentCount);
                  //split IDAttachmentCount by the # delimiter
                  var attachmentCount = IDAttachmentCount.split('#');
                  var attachmentCount = attachmentCount[1];
                  window.console  &&  console.log("attachmentCount = " + attachmentCount);
                  //check count and update Attachments? column
                  if(attachmentCount > 0){
                      window.console  &&  console.log("Attachments found: updating attachments column to Yes");
                      setFieldValue("attachmentsYN", "Yes");
                      setFieldValue("attachmentCount", attachmentCount);
                  }
      
                  if(attachmentCount <= 0){
                      window.console  &&  console.log("No Attachments: updating attachments column to No");
                      setFieldValue("attachmentsYN", "No");
                      setFieldValue("attachmentCount", attachmentCount);  
                  }
      
          }
          else {
              window.console  &&  console.log("no folder yet");
          }
      }
Viewing 5 reply threads
  • You must be logged in to reply to this topic.