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

Question

Question

SDK - Get Document By Template And Field Value

SDK
asked on April 10, 2015

Is there a function in the SDK to find a document based on a specified template and field value.  In other applications we are using GetEntryByID, but in this case the application does not know the documentID.  We can do this when constructing a weblink url search, however in this case weblink is not an option because of the sensitivity of the information.

1 0

Answer

APPROVED ANSWER
replied on April 10, 2015

You can use the SDK to run a search using the same search syntax as in your WebLink search URL. The SDK documentation covers searching and the general syntax for a template and field search is

{[TemplateName]:[FieldName]="Value"}

2 0
replied on April 13, 2015

Thanks Alexander, this helps!

0 0

Replies

replied on June 21, 2017

Good morning,

Sorry for hijacking this thread.  I have a similar need but don't have access to the SDK documentation at this time.  I need to build out a search string given a folder, templatename and possibly multiple values (fieldName & fieldValue) as provided by the user.  What is have will return all documents in a given folder, but I can't seem to get the syntax right to extend the search to a given template and (fieldName&fieldValue) pairs.  The line where searchParameters is being constructed is where I am stuck.

 

            string myFolder = @"Laserfiche\myFolder";
            string templateName = "General";
            string fieldName = "Document";
            string fieldValue = "document value";
            string searchParameters = String.Format("{{LF:Lookin=\"{0}\"}}", myFolder);

            Search lfSearch = new Search(session, searchParameters);
            SearchListingSettings settings = new SearchListingSettings();
            settings.AddColumn(SystemColumn.Id);

            lfSearch.Run();

            SearchResultListing searchResults = lfSearch.GetResultListing(settings);

            foreach (EntryListingRow item in searchResults)
            {
                Int32 docId = (Int32)item[SystemColumn.Id];

                EntryInfo entryInfo = Entry.GetEntryInfo(docId, session);
                if (entryInfo.EntryType == EntryType.Shortcut)
                    entryInfo = Entry.GetEntryInfo(((ShortcutInfo)entryInfo).TargetId, session);

                // Now entry should be the DocumentInfo
                if (entryInfo.EntryType == EntryType.Document)
                {
                    DocumentInfo docInfo = (DocumentInfo)entryInfo;

                }

            }

 

0 0
replied on June 21, 2017

You need to add " & {[TemplateName]:[FieldName]="Value"} "

0 0
replied on June 21, 2017

Use the LF client search pane to construct your search.  Add the "Field", "Within Folder", and "Search Syntax" as your search criteria. In the Field option, search by template, choose your template, and fill in your field value you are searching for.  In the Within option, fill in the path to search within.  Then run your search and the syntax will show up in the "Search Syntax" window.  You can then copy the syntax and paste it into you application and replace the static data in the syntax with your variables.

1 0
replied on June 21, 2017

Thanks for the replies.  

Bert - I was able to construct a search like you mentioned and return results but for the life of me, I can't locate anything that says or shows "Search Syntax"

I am unable to verify my searchParameters within my C# app at the moment due to "technical difficulties" but this is what it looks like.  Am I on the right track?

{LF:Lookin="Laserfiche\myFolder"}&{[SomeTemplateName]:[FieldName1]="Value1"}&{[SomeTemplateName]:[FieldName2]="Value2"}

 

0 0
replied on June 21, 2017

In the search pane, when you click the Customize Search, the last option is Search Syntax (in older versions, it may be labeled Advanced Syntax or something like that).

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

Sign in to reply to this post.