# How to most nicely write out the parameters for a named query

**URL:** <https://forum.inductiveautomation.com/t/how-to-most-nicely-write-out-the-parameters-for-a-named-query/105531>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [April 24, 2025, 6:39pm UTC](https://forum.inductiveautomation.com/t/how-to-most-nicely-write-out-the-parameters-for-a-named-query/105531 "2025-04-24T18:39:47Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon\_Hathout\_Willar](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@Simon\_Hathout\_Willar](https://forum.inductiveautomation.com/u/Simon_Hathout_Willar)\
**Post date:** [April 24, 2025, 6:39pm UTC](https://forum.inductiveautomation.com/t/how-to-most-nicely-write-out-the-parameters-for-a-named-query/105531/1 "2025-04-24T18:39:47Z")

</div>

A named query takes in a dictionary of parameters, which it uses to build the query. How to I most cleanly write out this dictionary?

Say I have a named query, located at `end_of_shift_reporting/create_report_entry`, which takes three parameters: `machining_shifts_ndx`, `operator_user_name`, `parts_produced_during_shift`, and returns the index that this new report was created at.  
I take in some data from a button event, calculate these three above parameters, and have them in variables named the same.

There are two ways I can think to approach this: declare a variable, put my params in it, and then pass it to the function, or I could have an anonymous variable instead.

```python
# first option
params_create_report_entry = {
		"machining_shifts_ndx": machining_shifts_ndx,
		"operator_user_name": operator_user_name,
		"parts_produced_during_shift": parts_produced_during_shift}
new_report_index = system.db.runNamedQuery(end_of_shift_reporting/create_report_entry, params_create_report_entry)

#second option
new_report_index = system.db.runNamedQuery(end_of_shift_reporting/create_report_entry, {
		"machining_shifts_ndx": machining_shifts_ndx,
		"operator_user_name": operator_user_name,
		"parts_produced_during_shift": parts_produced_during_shift})

```

Is there any particular (personal) preference between the two?  
Additionally, where do people like to put those parenthesis?

---

<div class="post-metadata">

**Author:** ![Benjamin\_Furlani](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/benjamin_furlani/32/66084_2.png) [@Benjamin\_Furlani](https://forum.inductiveautomation.com/u/Benjamin_Furlani)\
**Post date:** [April 24, 2025, 7:02pm UTC](https://forum.inductiveautomation.com/t/how-to-most-nicely-write-out-the-parameters-for-a-named-query/105531/2 "2025-04-24T19:02:06Z")

</div>

I normally use option #1

```Python
params_create_report_entry= {
		"machining_shifts_ndx": machining_shifts_ndx,
		"operator_user_name": operator_user_name,
		"parts_produced_during_shift": parts_produced_during_shift
}
new_report_index = system.db.runNamedQuery("end_of_shift_reporting/create_report_entry", params_create_report_entry)

```

I move the `}` to the bottom on it's own line.

I typically use camelCase insted of the `my_variable` naming scheme.

I also like short hand names for variable names and parameters, but long names can help with understanding exactly what it going on.

I would write what you have as follows:

```Python
queryParams = {
		"shiftsIndex": shiftsIndex,
		"opUserName": opUserName,
		"partsProduced": partsProduced
}
newReportIndex = system.db.runNamedQuery("endOfShiftReporting/createReportEntry", queryParams)

```

It will come down to personal preference really. I see some people do option 2 as well, and that is more compact code, but I like a variable especially when I am building the params from other variables.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [April 24, 2025, 7:16pm UTC](https://forum.inductiveautomation.com/t/how-to-most-nicely-write-out-the-parameters-for-a-named-query/105531/3 "2025-04-24T19:16:18Z")

</div>

> [@Benjamin\_Furlani](#):
>
> I typically use camelCase insted of the `my_variable` naming scheme.

I also use camelCase, but for me it less "personal Preference" and more, because that is the Java recommended scheme, and so when using Java functions in Jython, it makes my OCD not go crazy, from mixed naming schemes.

I also prefer short hand names, but don't fall into the "Microsoft" trap. I'm looking at you LPCWSTR, and Hungarian Notation.

---

<div class="post-metadata">

**Author:** ![Benjamin\_Furlani](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/benjamin_furlani/32/66084_2.png) [@Benjamin\_Furlani](https://forum.inductiveautomation.com/u/Benjamin_Furlani)\
**Post date:** [April 24, 2025, 7:48pm UTC](https://forum.inductiveautomation.com/t/how-to-most-nicely-write-out-the-parameters-for-a-named-query/105531/4 "2025-04-24T19:48:10Z")

</div>

I always notice when I see LLM stuff from people where the LLM throws the underscore scheme in there and the person puts their flavor on top of it not realizing. I probably only notice because I too have a hair of the OCDs when it comes to code.

---

<div class="post-metadata">

**Author:** ![Simon\_Hathout\_Willar](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@Simon\_Hathout\_Willar](https://forum.inductiveautomation.com/u/Simon_Hathout_Willar)\
**Post date:** [April 24, 2025, 8:11pm UTC](https://forum.inductiveautomation.com/t/how-to-most-nicely-write-out-the-parameters-for-a-named-query/105531/5 "2025-04-24T20:11:32Z")

</div>

oh, I'm completely a fan of camelCase (my background is java), it's just that all the code we have uses underscores, and I'd rather be constant in that regard.

One thing that I was not willing to be consistent on (and in fact went back and refactored) was prepending the name of any variable that was used in a named query with param\_.

(The main reason I refactored was because we had a giant dictionary of parameters for this application, that seven different queries went and added to/ wrote from as they went)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 24, 2025, 8:44pm UTC](https://forum.inductiveautomation.com/t/how-to-most-nicely-write-out-the-parameters-for-a-named-query/105531/6 "2025-04-24T20:44:19Z")

</div>

> [@Benjamin\_Furlani](#):
>
> ```python
> queryParams = {
> "shiftsIndex": shiftsIndex,
> "opUserName": opUserName,
> "partsProduced": partsProduced
> }
> newReportIndex = system.db.runNamedQuery("endOfShiftReporting/createReportEntry", queryParams)
> 
> ```

This, but (in my opinion) go a step further - if, out of frame, you're doing something like:

```python
shiftsIndex = referenceToComponent.custom.shifts_index

```

Or whatever... just do that inline in the dictionary declaration:

```python
queryParams = {
	"shiftsIndex": reference.custom.shifts_ndx,
	"opUserName": reference.custom.operator_user_name,
	"partsProduced": reference.custom.parts_prod
}
newReportIndex = system.db.runNamedQuery("endOfShiftReporting/createReportEntry", queryParams)

```

It's a pet peeve of mine to see `"someThingName": someThingName` - drives me crazy 😆

---

<div class="post-metadata">

**Author:** ![Leor\_Fishman](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@Leor\_Fishman](https://forum.inductiveautomation.com/u/Leor_Fishman)\
**Post date:** [April 24, 2025, 10:20pm UTC](https://forum.inductiveautomation.com/t/how-to-most-nicely-write-out-the-parameters-for-a-named-query/105531/7 "2025-04-24T22:20:19Z")

</div>

I actually don't mind this code, because i've definitely saved myself from bugs due to

```python
"someThingName": someThingElseName

```

immediately flagging itself to my eye as wrong where a more direct approach might not have been clear

---

<div class="post-metadata">

**Author:** ![bmusson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmusson/32/87530_2.png) [@bmusson](https://forum.inductiveautomation.com/u/bmusson)\
**Post date:** [April 24, 2025, 10:50pm UTC](https://forum.inductiveautomation.com/t/how-to-most-nicely-write-out-the-parameters-for-a-named-query/105531/8 "2025-04-24T22:50:49Z")

</div>

> [@paul-griffith](#):
>
> It's a pet peeve of mine to see `"someThingName": someThingName` - drives me crazy 😆

One of the few niceties of JS is [shorthand properties](https://ui.dev/shorthand-properties), every time I swap back to Python-land I miss it.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [April 25, 2025, 3:02am UTC](https://forum.inductiveautomation.com/t/how-to-most-nicely-write-out-the-parameters-for-a-named-query/105531/9 "2025-04-25T03:02:41Z")

</div>

> [@paul-griffith](#):
>
> It's a pet peeve of mine to see `"someThingName": someThingName` - drives me crazy

My favorite is when there is a setter and instead of using something like “newValue” the actual variable name is used, so you end up with:

```python
public void setSomeThing(someThing) {
     someThing = someThing
}

```

That hurt just writing it. 😆

---

<div class="post-metadata">

**Author:** ![Benjamin\_Furlani](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/benjamin_furlani/32/66084_2.png) [@Benjamin\_Furlani](https://forum.inductiveautomation.com/u/Benjamin_Furlani)\
**Post date:** [April 25, 2025, 3:30am UTC](https://forum.inductiveautomation.com/t/how-to-most-nicely-write-out-the-parameters-for-a-named-query/105531/10 "2025-04-25T03:30:16Z")

</div>

I love this about JS. It's this an spread that I miss when I come back to the world of python..

---

<div class="post-metadata">

**Author:** ![Simon\_Hathout\_Willar](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@Simon\_Hathout\_Willar](https://forum.inductiveautomation.com/u/Simon_Hathout_Willar)\
**Post date:** [April 25, 2025, 4:44pm UTC](https://forum.inductiveautomation.com/t/how-to-most-nicely-write-out-the-parameters-for-a-named-query/105531/11 "2025-04-25T16:44:18Z")

</div>

wait, do people not use `self` (or `this` for java) in those situations?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [April 25, 2025, 4:51pm UTC](https://forum.inductiveautomation.com/t/how-to-most-nicely-write-out-the-parameters-for-a-named-query/105531/12 "2025-04-25T16:51:32Z")

</div>

You would be surprised.

That will compile as is assuming the rest of the context is there.

Even adding the `this` doesn't make it much better. `this.someThing = someThing`.

---

<div class="post-metadata">

**Author:** ![Simon\_Hathout\_Willar](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@Simon\_Hathout\_Willar](https://forum.inductiveautomation.com/u/Simon_Hathout_Willar)\
**Post date:** [April 25, 2025, 4:56pm UTC](https://forum.inductiveautomation.com/t/how-to-most-nicely-write-out-the-parameters-for-a-named-query/105531/13 "2025-04-25T16:56:38Z")

</div>

It's still goofy looking, but at least it doesn't completely make no sense.
