Checkbox enabled

I have a checkbox for each day of the week. I need to log the selected day name to my database
when the checkbox is enabled and the ticket is created by clicking on create ticket button . How to proceed with this.
image

I would create a Named Query that collects the data in the fields and puts it in the database whenever you click the Create Ticket button.

on the Create Ticket button you can use an "onActionPerformed" event and use the system.db.runNamedQuery() function to log the data into the Database.
You can define the entire dataset of your named query within the runNamedQuery function.

Depending on how the data in the DB needs to be structured there are quite a few ways of solving this, but you will most likely have to do something within a script action like retrieving the properties of the fields and checkboxes.

1 Like

I Have created a script for my create ticket button which is able to read all other components value.
I want to know how to read the label of the checkbox only when enabled so that I can pass that value to the database table create

Here is the script linked to the create ticket button

def runAction(self, event):

Site=self.parent.parent.getChild("FlexContainer").getChild("FlexContainer_0").getChild("FlexContainer_3").getChild("site").props.value
AssetID=self.parent.parent.getChild("FlexContainer").getChild("FlexContainer_1").getChild("FlexContainer_1").getChild("FlexContainer_1").getChild("Assetid").props.value
ResponsiblePerson =self.parent.parent.getChild("FlexContainer").getChild("FlexContainer_1").getChild("FlexContainer_2").getChild("FlexContainer_2").getChild("ResponsiblePerson").props.value
ReportedBy =self.parent.parent.getChild("FlexContainer").getChild("FlexContainer_1").getChild("FlexContainer_2").getChild("FlexContainer").getChild("ReportedBy").props.value
Observation =self.parent.parent.getChild("FlexContainer").getChild("FlexContainer_3").getChild("Description").props.text
ticketStatus = 	"OPEN"
MONDAY=self.parent.parent.getChild("FlexContainer").getChild("FlexContainer_1").getChild("FlexContainer_1").getChild("FlexContainer_4").getChild("ToggleSwitch").props.select


if AssetID != '' and ResponsiblePerson != '' and ReportedBy != '' and Observation != '' and dayselection !='' and Site !='':
    system.db.runNamedQuery("CMMS/SCHEDULE_MASTER/insert_weekly_SCTK", {"ASSET_ID": AssetID, "RESPONSIBLE_PERSON": ResponsiblePerson, "REPORTED_BY": ReportedBy, "OBSERVATION": Observation, "TICKET_STATUS": ticketStatus , "DAY_SELECTION": dayselection,"SITE_NAME": Site})
    system.perspective.openPopup('errorMessage','Templates/General/messageBox',params = {'Text':'Weekly Schedule Maintainance Ticket Sucessfully Created'},modal=True,showCloseIcon=False,viewportBound=True)
    system.perspective.sendMessage('refresh',scope = 'page')
    system.perspective.closePopup('addNewTicket')
    system.db.refresh(event.source.parent.getComponent('Power Table'), "data")
	
else:
	system.perspective.openPopup('errorMessage','Templates/General/messageBox',params = {'Text':'Enter all the fields!'},modal=True,showCloseIcon=False,viewportBound=True)

Here is a small example of how you could solve it.

Here it checks if the check is toggled or not and only passes the label to the parameter if it is checked.
If you have a check for each day you just need to create some sort of logic to check all of the boxes if they are toggled or not.

Note that all the properties of all components are reachable through scripts so you can use conditional statements for every prop on every component if you need

1 Like

There is no checkbox component in your screenshot. Do you mean the "toggle switch"?

Tips:

Use the </> code formatting button to preserve code indentation and apply syntax highlighting in your posts. (Select the code and then click the button.) It's essential for Python and makes any code much easier to read. There's an edit button 🖉 below your post so you can fix it.

You can simplify the management of reading component values by binding each component's value to a custom property of the view.
For example, instead of

Site = self.parent.parent.getChild("FlexContainer").getChild("FlexContainer_0")
    .getChild("FlexContainer_3").getChild("site").props.value

create props.custom.Site and bind the site dropdown's value property to that. Now your code becomes,
Site = view.custom.Site
This is far easier to read and maintain and means that the code won't break if the view layout is changed or you have to move components in or out of containers.

2 Likes

I was about to say the same thing.
But just to make something clear, only bind up as @Transistor has, not down.
As in, bind child props to parent props; don't bind parent props to child props, otherwise things get messy

Thank you everyone for the help. I was able to resolve my issue.