Putting a list into a label to display values

Good morning,

I am working on an approval list. Essentially, all it does is take all employees first name, last name and clock number and display them to show that they have been approved. All of the approving is done from another page and returns a status field in the database = 1.

I have come up with a script to write out the approved employees first, last and clocknumber with the following script:

Date = DateData.value
returnedData = system.db.runNamedQuery("Overtime/Trade Tables/Mechanics Approved", {"Date" :Date})
system.tag.writeBlocking("[default]MOS/Mechanics Overtime Signups Saturday", returnedData)

pyData = system.dataset.toPyDataSet(returnedData)
for row in pyData:
	LastName = row[0]
	FirstName = row[1]
	ClockNumber = row[2]
	ApprovedShift = row[3]
	ApprovedSecondShift = row[4]
	print FirstName + " " + LastName + " (" + str(ClockNumber) + ")"

This script works in the Script Console, returning this list:

When I try to implement it on the approval list page I run into the problem of only getting the last return (in this case, "Terry. Francis (10027125)". I have it assigned to a label object. Is there a certain component I should be using for a returned list? Do I have to use a table or is there a way to parse this out? The count will not always be the same, so size of the component used also comes into question. I'd like to make this page printable so our maintenance managers can print it out and use it in meetings, so a table isn't quite ideal.

Thank you in advance for your help.

It would be more relevant to show us the script that doesn't do what you want, rather than the one that does.

But I'm going to guess and say you just replaced the print with an assignment to a variable, then returned that variable. Am I close ?

You'd need something like this:

pyData = system.dataset.toPyDataSet(returnedData)
return '\n'.join("{} {} ({})".format(row[1], row[0], row[2]) for row in pyData)

But I'd use a table instead. That's what they were made for. It would be simpler, look cleaner, and offer more flexibility than a label.

Bonus question: Why are you writing to a tag ? I don't think this should be done here.

1 Like

So, you're correct. I just assign the script inside of a datetime input and it then writes the return to the labels props.text field. The only reason I don't want to put it into a table is that I don't know how many entries there would be, so the table could possibly not show all rows and then they will be missing data when they go to print out the page. I'm looking for something like they had on the previous system included in a picture below:

I was writing to the tag because I was trialing different ways of looping, though it doesn't seem too useful in this scenario.

That's a bit different. Do you want to replicate this ?
If that's the case, you need the data about the shifts. I'll help with the script if required, but I can't do anything without more details.

If you'd rather stick to a list type display, I'd still suggest using a table.
Even if there's an arbitrary number of rows that wouldn't fit on a single page... The issue is the same with a label, and I'm pretty sure it would even be worse.

If the issue is that the table's results are split into several pages and thus not shown in its entirety, you can change the number of rows displayed. You could even change it at runtime depending on the length of your list.

Your solution seemed to have solved it for me, I'm sorting by the shift now and splitting it into several labels. However I'm not against changing to a table if you can change it at runtime based on length of the list. Is this something I would use the len() operator for?

Actually, all you'd have to do, is to disable the pager.
To do this, just uncheck both checkboxes here:
image

I'd still like to answer the len question though:
Yes. But with a little nuance.

First, since a table works well with datasets, you wouldn't have to convert it to a pyDataSet.
You can get the number of rows in a dataset with len.... in an expression. It won't work in a script, as basic datasets don't have a __len__ method.
In a script, you'd have to use their getRowCount() method, or just rowCount.

For pyDataSets it would be different. They do have a __len__ method, so you can call len on them in a script.

So, I ask this because I do have a page where the table lengths change as more people put in for overtime. They are JSON (sadly) as I have dropdowns within the tables that the maintenance manager uses to approve/deny operators. If I were to make the table size change based on the length (or count of signups), how would I push the other items further down (if this is possible)? I have 4 separate tables: one for mechanics, one for electricians, one for laborers and one for lube techs. Here's a picture for example:

Depends on the containers they're in.
For coordinate containers, you'll probably have to calculate the required height dynamically. I'm not used to coordinate containers, so you'd better wait for someone else's advice.
For flex containers... a combination of basis: auto and grow: 1 should do it, but if you have nested flex containers it can get a bit hairy to figure out how to set it up.