When using a Document Relationship in the repository, how can I find linked documents to a particular entry? Is there a search I can do to find those entries with the specific relationship type and relating to an entry of a particular ID? I have had no luck trying to set that type of search up yet.
Question
Question
In Workflow, How can I find the linked Documents from a Document Relationship
Answer
There is nothing built-in. You would have to use a script. See the GetEntryLinks method in RepositoryAccess or FindLinks in LFDocument in LFSO in your SDK documentation.
How would I go about traversing through the collection? Is it going to come back like an array would be?
Hi Kenneth,
Are you using VB.NET?
I had a similar task where I was trying to find the document ID's of all the documents that are linked to the starting entry in Workflow, so I set up the following script. (You would just need to change it to look at your server, repository, and specify a username & password to log in under)
Dim myRepoReg As Laserfiche.RepositoryAccess.RepositoryRegistration = New Laserfiche.RepositoryAccess.RepositoryRegistration("your server name", "your repository") Dim MySession As New Laserfiche.RepositoryAccess.Session MySession.LogIn("username","password",myRepoReg) Dim Entry as Integer = GetTokenValue("Entry ID") Dim IDList as String = "" Dim Links as EntryLinkCollection Dim Count as Integer = 0 Links = EntryLink.GetEntryLinks(Entry,MySession) For each Link as EntryLinkInfo in Links if Count = 0 Then IDList = Link.TargetId.ToString Count = Count + 1 Else IDList = IDList + "," + Link.TargetId.ToString End If Next SetTokenValue("LinkedDocumentIDs",IDList) 'MsgBox(GetTokenValue("LinkedDocumentIDs")) MySession.LogOut
This brings back a list of the linked Document ID's in the token LinkedDocumentIDs delimited by a comma. If you were looking for only documents linked with a specific relationship you could probably add more IF/ELSE conditions in the For Each section.
It's not great but I hope it helps!
Dom
Workflow SDK scripts provide a connection already to Laserfiche so I would recommend the script above but without the login/logout portion.
In WF 9.1, that would be
Dim mySesssion as Session = me.RASession
In addition, the entry id can be retrieved by calling:
me.BoundEntryId or
me.LaserficheApi.StartingEntryId or
me.LaserficheApi.BoundEntryId
Dom,
If you're using that script in Workflow, you should use the built-in connection rather than making your own. Workflow cleans up its own script connections, but your script could leave open connections if something goes wrong.
In WF 9.1, RepositoryAccess is the default reference for SDK Script activities, so use something like this:
Dim Entry as Integer = me.BoundEntryId Dim Session as Session = me.RASession Dim IDList as String = "" Dim Links as EntryLinkCollection Dim Count as Integer = 0 Links = EntryLink.GetEntryLinks(Entry,Session)
In WF 9.0, you have to install RepositoryAccess first and then add it as a referenceto your script, but then you can just tell WF to use it as the script connection:
Dim wrapper as ConnectionWrapperRA = me.ConnectToRA(ConnectionMethodRA.RepositoryAccess90) dim docinfo as Laserfiche.RepositoryAccess.Documentinfo = wrapper.BoundEntry
Thanks for the tips!
I didn't realise you could use the RepositoryAccess reference in version 9.0 - whereabouts could I install it if I was running WF 9.0?
Thanks,
Dom
You could get it by installing the SDK runtime.
Can someone post a full script that does the job?
Hi Ken,
If I remember correctly this was the script I finally ended up using:
Dim MySession as Session = me.RASession Dim Entry as Integer = me.BoundEntryId Dim IDList as String = "" Dim Links as EntryLinkCollection Dim Count as Integer = 0 Links = EntryLink.GetEntryLinks(Entry,MySession) For each Link as EntryLinkInfo in Links if Count = 0 Then IDList = Link.TargetId.ToString Count = Count + 1 Else IDList = IDList + "," + Link.TargetId.ToString End If Next SetTokenValue("LinkedDocumentIDs",IDList) 'MsgBox(GetTokenValue("LinkedDocumentIDs"))
I then used the Split Function found in Token Dialogue... to separate the EntryID's returned from the script and put them into a multi-value token. (whenever a "," is found).
Hi Dominic,
I haven't looked at this in a while, but assuming my cursory look at the code is accurate and that code runs perfectly, then you using the function of Split on every , would work to give you a multi-value token with the various IDs.
I would rather have a Find Links over a Delete Links so that we can determine what to do with the links just like with the Find Entries activities.
This script worked perfectly for me and just saved me hours!!!! Yaay Laserfiche Answers and Dominic!!!!
Is this ability being considered as a new activity in a future version of Workflow?
As someone who does not understand much of what was said above, but none-the-less still need to find all linked entries, I would greatly appreciate this being a drag and drop activity in future versions.
Is this possible yet in Workflow 10.2 without needing to use the SDK? Thanks
Not as of 10.2. There weren't a lot of new features for Workflow in 10.2
Please please please please please please please please please. Get it into 10.3....... It sure would help.
Agreed, we're have multiple clients with need for this functionality.
I solved this by using the SDK Script someone posted elsewhere on this site and it worked.
Late post; we have developed a custom workflow activity that will retrieve the linked entries associated with any selected repository entry. The custom activity returns an entry collection that can be used to feed a For Each Entry activity to allow you to iterate through the link collection. Other link properties returned are the link entry ID, link relationship, link reverse relationship, and link description. Here is a screen shot of the custom activity properties pane;
This and other custom workflow activities are available on the Products page of the Qfiche website at http://qfiche.com/products. The custom workflow activities available for download are fully functional 30 day demos.
Thank you - this SDK script worked perfectly!