Display the embedded view based on the DB data

I have two embedded view. I want to show the embedded view based on the data which is fetched from Db.
This is my DB data fetched look like dict.

I am trying to create a expression binding in each embedded view VISIBILITY property.
Here is my expression look like:
"len([machine for machine in self.session.custom.machineparmses if machine['machinenumber'] == 'm002' and machine['utilized'] == 'yes']) > 0"

main condition is, if utiulized is 'yes' ,visibility = true, else false.
not sure it is correct.not working. Kindly give me correct solution.

First things first: switch to a boolean. Don't use strings to indicate a boolean state.
Then, why are all these things in the session custom ?

What you showed is NOT a valid expression, it's python code. And I'm not sure what its goal is. Why is len involved ?
How are the embedded views displayed ?
Wouldn't a flex repeater be more suited ?
The whole thing smells like an xy problem. Describe what the end goal is, we'll help you figure out how to do it.

But to answer the initial question: If your views have a parameter that says "yes" or "no", and you want the visibility of the view to it... view.params.utilized = 'yes' will do it.
But it really should be a boolean.

3 Likes

Thank you for your reply.
That session property is querying the data from named query and stores here to access in all views.
Querying and storing the data in session custom property looks like:

data = system.db.runNamedQuery("machine-utilized", {}) 	utilizedMachines = []
	for row in range(data.getRowCount()):
	   	 machine = {
	        "batchnumber": data.getValueAt(row, "bacth_number"),
	        "machinenumber": data.getValueAt(row, "machine_no"),
	        "utilized": data.getValueAt(row, "utilized")}	
		 utilizedMachines.append(machine)


	self.session.custom.machineparmses = utilizedMachines

My ultimate goal is to show the embedded view that has based on machine number and 'utilized' column has 'yes'
This machine number will be there in all embed view as custom property.
So it will check the machine number and that machine number is utilized or not, that is 'yes', 'no'.

I have not even think about that initially to go with flex repeater. so i have create embed. Completed the design on embed view, so will very useful if you provide solution on this.

if you are not using any client based parameters. you could store this data in a tag, instead of requesting it for every client. This will grately imporve performance if you have many clients.

If all your views are the same apart from the machine numbers and the "utilized" You can make one view which uses these as view params and than you can easily supply a flex repeater these params

2 Likes

Thank you for your reply. I got your, As we have completed the development. This is last phase addition. So not able to start from flex. Kindly give your inputs on embedded view visibility property.
I have list of dict as session custom property. just need to verify the two key.values, that is machine number and utilization.
machine number will verify over label component.

Again:

This is all you need.

2 Likes

Thank you. As you said, I have my data in dictionary format, how can I verify that utilize and machine alone.
Can you please help me to provide the expression.

You want to do it from outside the view ?
Frankly, just use a flex repeater.
Bind the props.instances property to your dict, then add a script transform like this:

return [v for v in value if v['utilized'] == 'yes']
2 Likes

Thank you. Will try that