08-09-2018 01:29 PM
Hello,
I'm trying to create a script that will pull documents based off of a custom query I have set up. The custom query itself works fine in the client, but when I try to connect to the api via a script and run the query I am getting a NullReference exception. Has anyone else ever experienced this? The Hyland.Unity.dll version is 16.0.2.83. Even the if statement errors out. Like the CustomQueries library doesn't exist in the API or something.. Do we need a special license type to accomplish this?
if(app.Core.CustomQueries != null) { try { Console.WriteLine(app.Core.CustomQueries.Count); } catch (UnityAPIException ex) { Console.Write(ex); app.Dispose(); } }
08-10-2018 06:28 AM
Speculating because there isn't enough information. Is this run outside (Unity API) or inside (Unity Automation API)? If it's outside are you connecting Session first?
Also, I could be totally off, but I don't think you can test null against app.Core.CustomQueries like that without instantiating it first.
Mind, if this is just a snippet you may have accounted for these.
08-10-2018 06:19 AM
I was able to get this working with a regular document query. No Custom Query needed. Still, I'd like to know why that was happening with the custom queries?
08-10-2018 06:28 AM
Speculating because there isn't enough information. Is this run outside (Unity API) or inside (Unity Automation API)? If it's outside are you connecting Session first?
Also, I could be totally off, but I don't think you can test null against app.Core.CustomQueries like that without instantiating it first.
Mind, if this is just a snippet you may have accounted for these.
08-10-2018 06:57 AM
This was in the regular Unity API, I haven't worked with Automation yet, so that may be the problem. Not exactly sure how to instantiate CustomQueries? I don't see any "Init()" function and I'm pretty sure making a new object out of it wouldn't work. Also, yes, I was connected with a session.
Still kind of new to the API, so I'm sure I was doing something wrong.
08-17-2018 08:49 AM
That's why I was asking. So take the following nonfunctional snippet:
Application app = null;
AuthenticationProperties props = null;
app = Application.Connect(props);
Core core = app.Core;
CustomQuery query = core.CustomQueries.Find("myQuery");
Bold is the instantiate I'm referring to, in this case.
so now query would get you over to attributes of the query, but I don't believe it would let you actually execute and return results.
You then go to
DocumentQuery documentQuery = core.CreateDocumentQuery();
documentQuery.AddCustomQuery(query);
Which tells it use what it got from the first CustomQuery to run a DocumentQuery. Then pass parameters and execute/display results. Wrapping that in your If/Then to catch Null, or even better, Try/Catch to catch any exception, should do what you're trying to do.
This is all off the top of my head, so if anyone thinks I'm off please do share here.
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.