Home › Forums › vLooup for SharePoint › Count files in child folder when using the vLookup Add new Folder / doc library
- This topic has 6 replies, 2 voices, and was last updated 4 years, 10 months ago by Alexander Bautz.
-
AuthorPosts
-
-
January 13, 2020 at 19:56 #28209
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?
-
January 14, 2020 at 19:29 #28220
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
-
January 16, 2020 at 01:52 #28265
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:
-
January 16, 2020 at 19:46 #28282
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
-
January 16, 2020 at 21:14 #28284
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>
-
January 17, 2020 at 07:40 #28288
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"); } }
-
January 17, 2020 at 17:12 #28294
I’m glad you figured it out!
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.