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

Question

Question

Custom Query Editor

asked on November 8, 2017 Show version history

Good morning,

 

I'm trying to pass a value from a form field into a declared variable using the Custom Query Editor in WF. I was following the manual here: https://www.laserfiche.com/support/webhelp/workflow/9.0/en-us/content/resources/Activities/Custom%20Query%20Property%20Box.htm but I might be missing something because I get errors when I tried to use it similarly. 

 

My code looks like this:

DECLARE @startdate datetime2 =  '2017-10-06'; 
DECLARE @enddate datetime2 = '2018-10-06';  
DECLARE @interval varchar(10) = 'month'

and what I want to do next is replace the startdate with some type of parameter so I'm doing this now

DECLARE @startdate datetime2 = ?; 
DECLARE @enddate datetime2 = '2018-10-06';  
DECLARE @interval varchar(10) = 'month'

and at the bottom I have the Parameter Names field as ? and Type String and Parameter Value to a form field value (see screenshot)

but I get the error as in the second screenshot.

Any guidance on how to properly configure this?

 

Thank you,

Raul Gonzalez

 

UPDATE: I see that someone posted the same issue without a clear result here as well: https://answers.laserfiche.com/questions/68098/Having-trouble-with-a-custom-SQL-query-that-works-perfectly-in-Quick-Fields-83-but-reports-an-error-in-Workflow-91?sort=newest

screenSQL.png
incorrectSQL.png
screenSQL.png (11.47 KB)
0 0

Answer

SELECTED ANSWER
replied on November 8, 2017

Hi Raul,

How are you connecting to the DB? Directly or with ODBC? Question marks are used in place of named parameters only in the case of ODBC connections. Without more screenshots/properties information, my best guess is that the connection type does not match up with the parameters being used.

If connection type is the issue, either change it, or name your parameter something like '@myParameter'. You might also be able to avoid having to declare SQL variables by passing the parameters directly into the query.

~Rob

2 0
replied on November 8, 2017 Show version history

Thanks Rob,

It seems that the setting in the Wizard is "Direct Connection" first and then on the next screen the drop-down menu for Data Source Type is "ODBC" and Data Source Driver "Sql"

I tried updating the sql to the screenshot below, and now I get a different error (see second screenshot).

 

Date.png
Error.png
Date.png (6.49 KB)
Error.png (5.48 KB)
0 0
replied on November 8, 2017

Rob, I changed the value of the "Type" of the drop-down menu from "Date Time2" to "Default" and although I got yet another different error, the form did not terminate when I ran it.

I think this should allow me to move forward with what I was trying to do. Thanks for pointing out the correct settings of Direct vs ODBC.

Thank you,

Raul Gonzalez

Error2.png
Error2.png (5.73 KB)
0 0
replied on November 8, 2017

Good, I'm glad updating the connection settings is yielding results.

As an aside, I would recommend avoiding declaring anything in your query and doing something more like this instead:

3 0
replied on November 18, 2020

This was super helpful. I had a simple query that wouldn't run. I've been using '?' for all variables. Which I thought was how it was done. 

Anyway, switching to an '@email' did the trick. I was seriously getting disillusioned there for a bit. 

0 0

Replies

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

Sign in to reply to this post.