I am using a Flex Repeater and a Query binding on the instances PROP of that flex repeater in order to populate it using the following query:
select job_number as JobNumber
from jobs
JobNumber is the name of a parameter in the template I am using in the flex repeater. However, I have another parameter on my template that I need to pass but it is only available on a tag, a State value. Each Job has a tag with the State value I am looking to grab. How can I append that tag or State value to the instances parameter?
This is built off of the example from IU:
I can’t quite see the problem. You have two parameters: JobNumber has an SQL query binding; the other has a tag path binding. Is the problem with the tag path binding not working? Perhaps you can show the tag binding configuration.
Within your binding, you’ll need to add a transform step. The logic below will need to be altered according to how you’re obtaining the State for each JobNumber. Also, my example assumes you’ve converted the NamedQuery binding return type to JSON instead of auto or dataset.
mainline_tag_path = "[default]SomePath/{0}" # this represents the path to your state tags, and assumes they all use the same format/path and that they are identified by a JobNumber
# Construct a list of target paths based on the returned JobNumber values
target_paths = [mainline_tag_path.format(entry["JobNumber"]) for entry in value]
# read those paths and store them as Qualified values
tags_as_states = system.tag.readBlocking(target_paths)
instances = []
for i in range(len(value)):
# now make new instance objects for each JobNumber and include the State from your tag
instances.append({"JobNumber": value[i]["JobNumber"], "State": tags_as_states[i].value}) # make sure to pull out the value of the tag
return instances
Okay so the template that the Flex Repeater is using has two paremeters, JobNumber and JobState. JobNumber has no binding, it is just an input field. JobState is bound by an indirect tag path like so:
[default]Job/Job{JobNumber}/State
so it references the JobNumber parameter in order to pull the correct state value for each Job.
The Query Binding pulls the JobNumber from a database as the query suggests and populates each of the instances with a Parameter of JobNumber: # but since the database does not store the state values, I have to get each Jobs State from its tag.
The issue is that in the Flex Repeater instances the only parameter the query includes is the JobNumber parameter, but I also need the JobState parameter so that I can order the instances based on each jobs state value. Now I can Sync Params, however that only lasts until I save my designer because the query binding is run again and doesnt pull the JobState since it isnt in the database.
Actually never mind now for whatever reason it is not removing the JobState parameter after I manually added it using the Sync Params button on each instance. Not sure what changed to let me keep them now as beforehand they were being removed.
Now I just have to try and sort them where jobs with State = 1 are at the bottom of the instances list.
I am indeed using the return format of json, however trying your code it returns a Parse Error in script transform…
I should have clarified that was all pseudo-code. Without your tags in place and some sort of data to work with I can’t give you the exact script you need - only an idea of what to do.
I suspect it was a typo in tags_as_states
. I’ve removed the typo in the snippet
1 Like
Gotcha as for that typo, I did catch that when typing your code into my script.
As for my tags, my Job tag looks like this (where # is a number 1 thru 10):
[default]Job/Job #
And the State of a job comes like this, one level into the Job tag:
[default]Job/Job #/State.value
If I am understanding how your code works I think I have added my tags into it correctly, but I will assume not as I do receive an error:
mismatched input '\\n' expecting set null
. Which looks to me like it is expecting a space within my code that I didnt specify but I am not certain, I have never seen that error before but looks like a newline character.
# this represents the path to your state tags, and assumes they all use the same format/path and that they are identified by a JobNumber
mainline_tag_path = "[default]Job/Job {0}/State" #there is a space between Job and the # in my tag path
# Construct a list of target paths based on the returned JobNumber values
target_paths = [mainline_tag_path.format(entry["JobNumber"]) for entry in value]
# read those paths and store them as Qualified values
tags_as_states = system.tag.readBlocking(target_paths)
instances = []
for i in range(len(value)):
# now make new instance objects for each JobNumber and include the State from your tag
instances.append({"JobNumber": value[i]["JobNumber"], "State": tags_as_states[i].value}) # make sure to pull out the value of the tag
return instances
The formatting of the forums can be weird. Anywhere you see an indent, delete it and replace it with a tab entry - it sometimes gets read as spaces here on the forums, and that is invalid spacing in Jython.
OR, it could be the hanging .
at the VERY end of the code.
Sorry, The forums always assume that a double space means that I want a .
when really I’m just trying to format comments.
": tags_as_states[i].value}). # <-- this guy
1 Like
Yeah I just noticed that little . at the end of that same line and removed it. That did fix the \n error however there is now a different one:
RuntimeError maximum recursion depth exceeded (Java StackOverflowError)
occurs on:
instances.append({"StationNumber":value[i]["JobNumber"], "State": tags_as_states[i].value})
Seems to me like this somehow exceeds the allowed number of recursion (I think 999 calls) in Python. The database only has 10 rows so I cant see how that is possible.