Jump to content

Data Validation for Report Header Parameters


---
 Share

Recommended Posts

---

I am working in Calypso 2025. I have a variable I created called u_Work_Order. I have enabled this parameter under Run and Measurement for my report header. I have also enabled Force Input at Start. A pop-up box appears right after the user hits run that asks them to enter in the WO. I would like to validate that the WO they entered is exactly 10 characters. 

I have been told I need to use PCM for this. I have tried creating my PCM program two different ways: first is by placing the code in a .txt file and then placing it in the root of the measurement plan program. I have also tried placing the code in the pre-settings with a global scope. 

I have tried every possible variation of code. Below are some I have tried. I always get an error like u_Work_Order is not defined or Temp_Variable is not defined. 

 

u_wo_number = ""
repeat
  u_wo_number = inquireText("Please enter 10-digit WO Number")
  if len(u_wo_number) != 10 then
    message("Error: Must be 10 characters. You entered: ", len(u_wo_number))
  endif
until len(u_wo_number) == 10

 

 

u_wo_number = ""
while len(u_wo_number) != 10 do
  u_wo_number = inquire( "Please enter 10-digit WO Number" )
  if len(u_wo_number) != 10 then
    display( "Error: Must be 10 characters. You entered: ", len(u_wo_number) )
  endif
endwhile

 

 

u_wo_number = ""
while len(u_wo_number) != 10 do
  u_wo_number = inquireText("Please enter the 10-digit WO Number:")
  
  if len(u_wo_number) != 10 then
    message("Error: The WO number must be exactly 10 characters. You entered ", len(u_wo_number))
  endif
endwhile

message("WO ", U_wo_number, " accepted. Starting measurement.")
Link to comment
Share on other sites

---

Be careful with Repeat commands because you do not have a break condition, so it will run indefinitely. 

Link to comment
Share on other sites

---

Please sign in to view this username.

 GPT gives me this:

 

wo = getRecordHead("u_Work_Order")

IF STRLEN(wo) <> 10 THEN
    MESSAGE("WO must be exactly 10 characters.")
    STOP
ENDIF

 

Since the variable (wo) already exists ("u_Work_Order", entered manually at Run), you just need to validate it, not ask for it again. I do not have PCM to verify (might not be STOP, I think it is CNCBreak()?), but the logic makes sense. Been quite awhile since I have used PCM. From this core code, you can expand on it and enforce more rules (for instance, not allowing someone to just type '0000000000' 🤣)

Edited
Link to comment
Share on other sites

---

endInspection() is better than cncBreak(). cncBreak will redlight the machine. There are cases though where cncBreak is the only thing that will stop a loop though. 

  • Like! 1
Link to comment
Share on other sites

---

you're definitely on the right path, just remember Calypso uses it's own version of small talk programming language. Your code appears right for python and similar languages, I haven't yet got GPT to spit out any useable smalltalk code for Calypso.

 I no longer have PCM access directly otherwise I would test it out for you.

 

Link to comment
Share on other sites

  • 3 months later...
---

I started doing something similar, then the operators just typed random characters to fill the value.

Now I am still looking at a "Black List" of characters and coding it in PCM, or perhaps, if possible, have a script check the values and redirect.

And that just gave me an idea.

I already have an interface for selecting part numbers, I can transfer the 4 required fields to the interface, remove from Calypso and check values there where it's a lot easier to code in VB.net. I can then call the 4 fields from the para file I generate.

Now I have another task.

Link to comment
Share on other sites

  • 2 weeks later...

Please sign in to view this quote.

Please sign in to view this username.

 You  can use regex (regular expression) to enforce the length, allowed characters, and character positions and patterns of the desired string.

Lets say the Work Order is exactly 10 characters, the first two characters are letters (perhaps WO), and the remaining 8 characters are numbers. 

In PowerShell, that snippet would look like this (copy into PowerShell ISE to test functionality):

 

# Work Order format:

# - Exactly 10 characters

# - First 2 characters must be uppercase letters (A-Z)

# - Last 8 characters must be digits (0-9)

# Example: WO12345678

 

$WORegex = '^[A-Z]{2}[0-9]{8}$'

 

do {

$WorkOrder = Read-Host "Enter Work Order Number"

if ($WorkOrder -cnotmatch $WORegex) {

Write-Host "Invalid Work Order Number." -ForegroundColor Red

Write-Host "Format must be 2 uppercase letters followed by 8 digits (Example: WO12345678)." -ForegroundColor Yellow

}

} until ($WorkOrder -cmatch $WORegex)

Write-Host "Accepted: $WorkOrder" -ForegroundColor Green

Link to comment
Share on other sites

 Share

×
×
  • Create New...