You are viewing limited content. For full access, please sign in.

Question

Question

How to Find Documents Without Shortcuts

asked on January 15, 2019

I am needing to create a workflow that searches a folder for documents and returns documents that do not have shortcuts and then process those documents on. Does anyone have a way to find documents that don't have shortcuts?

I know it is possible to search a folder and use the Retrieve Shortcuts activity to find out if a document has them, but I would rather not have to process every single document to find out if it has shortcuts if I can just start with those that don't instead.

1 0

Answer

SELECTED ANSWER
replied on January 16, 2019 Show version history

I apologize. I just realized I royally messed up worse than I thought when I was reformatting the document to post here.

SELECT t0.tocid AS Tocid
FROM toc AS t0
WHERE (((
    SELECT COUNT(*)
    FROM LF_Repository.dbo.toc AS t1
    WHERE t1.linkto = t0.tocid
    )) = 0) AND (t0.parentid = 1234)

This one is triple checked against my repo.

0 0

Replies

replied on January 15, 2019

In the past I've done something like this directly in the database:

SELECT tocid
FROM toc AS t0
LEFT OUTER JOIN toc AS t1 ON t1.tocid = parentid
WHERE (((
    SELECT COUNT(*)
    FROM toc AS t2
    WHERE t2.linkto = tocid
    )) = 0) AND (t1.parentid = 1234)

Then you load the entry ids into a staging table and run a workflow off of it.

 

1 0
replied on January 16, 2019

Devin, is there a way to change the query to just pull all that do not have a link? In your example it is querying specific id numbers.

0 0
replied on January 16, 2019 Show version history

Sure, that's easy enough. The reason I provided a parent id, is so that you can find anything within a specific folder. Sometimes I'll search everything with a parent that has a specific parent so that I can search an entire folder tree.

SELECT tocid
FROM toc AS t0
LEFT OUTER JOIN toc AS t1 ON t1.tocid = parentid
WHERE (((
    SELECT COUNT(*)
    FROM toc AS t2
    WHERE t2.linkto = tocid
    )) = 0)    -- just remove the AND, 
               -- the zero is there because we're counting up the 
               -- documents that have a shortcut pointing to them,
               -- and we want to find the ones with none

Let me know if the SQL is too obtuse. I think better in C#, and tend to experiment and write my queries as LINQ statements in LINQPad and then clean up the generated SQL.

0 0
replied on January 16, 2019

Devin, I understand now. We will need to actually exclude results that have specific parent ids. That gets a little trickier though as the main folder we want to exclude has 2 levels of subfolders.

0 0
replied on January 16, 2019 Show version history

This is another reason why it can be a good idea to use a staging table. For really complex cleanup jobs, I'll do a number of queries, and each time add the results to the temporary table. That way, my queries are simpler and easily validated. Then at the end, it's trivial to run a workflow or SDK script against the compiled data set.

1 0
replied on January 16, 2019 Show version history

Devin, is this the correct syntax?

SELECT t0.tocid
FROM toc AS t0
LEFT OUTER JOIN toc AS t1 ON t1.tocid = t0.parentid
WHERE (((
    SELECT COUNT(*)
    FROM toc AS t2
    WHERE t2.linkto = tocid
    )) = 0) AND (t1.parentid != 1)

It did not like just the tocid after SELECT or the parentid at the end of hte LEFT OUTER JOIN.

0 0
replied on January 16, 2019

Yeah, you've got it. I messed up when I was reformatting the query.

0 0
replied on January 16, 2019

So it looks like it's not working correctly. I added a document at the top of the repository so its parentid = 1. I did not create a shortcut for it. I then ran the following query:

SELECT t0.tocid
FROM toc AS t0
LEFT OUTER JOIN toc AS t1 ON t1.tocid = t1.parentid
WHERE (((
    SELECT COUNT(*)
    FROM toc AS t2
    WHERE t2.linkto = tocid
    )) = 0) AND (t1.parentid = 1)

And it did not bring back anything.

1 0
SELECTED ANSWER
replied on January 16, 2019 Show version history

I apologize. I just realized I royally messed up worse than I thought when I was reformatting the document to post here.

SELECT t0.tocid AS Tocid
FROM toc AS t0
WHERE (((
    SELECT COUNT(*)
    FROM LF_Repository.dbo.toc AS t1
    WHERE t1.linkto = t0.tocid
    )) = 0) AND (t0.parentid = 1234)

This one is triple checked against my repo.

0 0
replied on January 16, 2019

Thank you for all your help with this. This is what I ended up with so it only pulls documents and not folders:

SELECT t0.tocid AS Tocid
FROM toc AS t0
WHERE (((
    SELECT COUNT(*)
    FROM dbo.toc AS t1
    WHERE t1.linkto = t0.tocid
    )) = 0) AND (t0.parentid = 1234 AND etype = -2)

 

1 0
replied on January 16, 2019

You can also run the SQL from a workflow activity, the results will end up in a token and you can loop through them.

1 0
replied on January 16, 2019

Yep. This works great for smaller numbers of documents. For large batches, I tend to go with the intermediate table so that I can have a "done" column that gets checked off during the process. Then, if there's an issue, you can start where you left off. For this particular case, the ability to start where you left off is built in, so it's not needed.

1 0
replied on January 16, 2019 Show version history

Here's two more of my finest cents. When precessing documents in SQL, normally I filter out items in the recycle bin. Is that an issue for this script? I'm replying from my phone  so can't test. 

1 0
replied on January 16, 2019

It depends. The scripts I posted are minimum samples to demonstrate the concept. The first script is looking in a specific folder, so it's not a problem. The second script doesn't explicitly exclude the recycle bin, but that's a good thing to consider.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.