Good day! I have additional info for this topic, this was originally a project my coworker was working on and now has been passed to me. I have an āassignā button with the script
AssignedTo = self.getSibling("Dropdown_Assigned").props.value
Status = self.getSibling("Dropdown_Status").props.value
# ID = self.getSibling("Dropdown_Status").props.value
# Priority =
system.db.runPrepUpdate("UPDATE ShiftMaintWO SET AssignedTo = ?, Status = ?, Priority = ? WHERE ID = ?",[AssignedTo, Status, Priority, ID,])
CompleteTime = system.date.now()
CompleteShift = system.tag.read("Twisters/Current Shift").value
CompleteUser = system.security.getUsername()
if Status == 2:
system.db.runPrepUpdate("UPDATE ShiftMaintWO SET CompleteTime = ?, CompleteShift = ?, CompleteUser = ? WHERE ID = ?",[CompleteTime, CompleteShift, CompleteUser, ID,])
window = system.nav.openWindow('Main Window')
system.nav.centerWindow(window)
system.nav.closeParentWindow(event)```
on it. My co worker says the original idea was to have that populate this query table
SELECT
WorkOrder
,SubmitShift AS āShiftā
,SubmitTime
,Equipment
,Description
,AssignedTo
,CASE
WHEN Status = 1 THEN āOpenā
WHEN Status = 2 THEN āCompleteā
WHEN Status = 3 THEN āHoldā
When Status = 4 THEN āActiveā
END AS āStatusā
,SubmitUser
,Priority
,ID
FROM ShiftMaintWO
WHERE Status = 1
OR Status = 3
OR Status = 4
OR SubmitTime > dateadd(hour, -8, getdate())
ORDER BY CASE
WHEN Status = 1 THEN 2
WHEN Status = 2 THEN 4
WHEN Status = 3 THEN 1
When Status = 4 THEN 3
END ASC```
Not really, you still have your ID variable commented out, you didn't say anything about whether you tried to print out your parameters before running the prepUpdate to see if they are expected values, and you didn't include the database connection in the prepUpdate as suggested....
The # symbol in the script causes the line to be commented out, meaning it is not run as part of the script.
# ID = self.getSibling("Dropdown_Status").props.value (This line is commented out)
database = 'nameOfMyDBConnection'
system.db.runPrepUpdate("UPDATE ShiftMaintWO SET CompleteTime = ?, CompleteShift = ?, CompleteUser = ? WHERE ID = ?",[CompleteTime, CompleteShift, CompleteUser, ID,], database = database)
The biggest difference is that scripts in perspective run in a Gateway scope.
When you run some functions like system.db.runPrepUpdate in Gateway scope you will need to provide additional information. In this instance what database connection to run the query against.
When running in a vision client, if you don't provide the database connection, then the default connection is assumed. Thus the script works in a vision client, but not in perspective.
Notice how in the Gateway scope the database parameter is required and how in vision client scope the database parameter is optional (denoted by the [ ] surrounding it?
I will give you that it is a bit confusing that it also state that syntax will work in perspective session scope, in my experience it's best to assume that code will be running in the Gateway.
Get in the habit of always providing the database and you wont run into this particular problem.
No, it shold be the name of the database connection to the database that has the Table ShiftMaintWO.
system.db.runPrepUpdate("UPDATE ShiftMaintWO SET CompleteTime = ?, CompleteShift = ?, CompleteUser = ? WHERE ID = ?",[CompleteTime, CompleteShift, CompleteUser, ID], `database connection name`)
To get the name of the database connection you can find that on the Gateway at Config->Databases->Connections The name in the āNameā column is what you want to use.
So I was thinking about trying to use a runNamedQuery. I have this so far:
assignedto = self.getSibling("Dropdown_Assigned").props.value
status = self.getSibling("Dropdown_Status").props.value
id = self.getSibling(self.session.custom.ID).props.value
priority = self.getSibling("Dropdown_Prority").props.value
namedQuery = "WOupdate"
parameters = {"assignedto":"bob", "status":1, "priority":3, "id":45022}
system.db.runNamedQuery(namedQuery, parameters)
# CompleteTime = system.date.now()
# CompleteShift = system.tag.read("Twisters/Current Shift").value
# CompleteUser = system.security.getUsername()
# if Status == 2:
# system.db.runPrepUpdate("UPDATE ShiftMaintWO SET CompleteTime = ?, CompleteShift = ?, CompleteUser = ? WHERE ID = ?",[CompleteTime, CompleteShift, CompleteUser, ID,], database = database)
system.perspective.navigate('/wo_assign')
If i comment out everything except the navigate portion the button does navigate, so I know I have a Scripting error in the system.db.runNamedQuery. Can anyone tell me where Im going wrong on this?
In google chrome Control+Shift+I shows the browser console (or console in your Designer). Or it might appear in the gateway server logs - not 100% sure but its going to be in one of those two.
Without your full script itās hard to tell what line 4 is, I am guessing it is this though
id = self.getSibling(self.session.custom.ID).props.value
as .getSibling is trying to coerce a value into a string but it canāt, and the rest of your lines have hardcoded strings so it is not them (you would get a different sort of error if you did something like self.getSibling('thisDoesntExists").props.value, Iād guess saying NoneType has no props.). Since you can see the line numbers, itās on line 4.
This is not how you would reference a session property. self.getSibling() is used to retrieve another component in the same container as this component. The correct syntax would be something like
lrose, Thanks. That writes. When I select a row in that table, it populates some dropdowns and if i do not reselect data for those dropdowns it writes nothing to that table. How can I make sure it keeps that prepopulate data in the dropdowns and rewrites to the table? like if i had to modify one of dropdowns, but not the others.