Ignition expression and scripting functions

scripting
ignition80
#1

Hello,
Can i use the expression functions to a button in scripting?
for example i have a dataset that contains item code,i have to lookup to that dataset to see if there are same item codes and should pop up a message box if it contains the same code.

0 Likes

#2

No, you can’t use the Expression language inside a Jython script. However, the Jython language is far more powerful and extensible than the Expression language.

You can easily do dataset manipulations with Jython. Take a look at the system.dataset scripting functions in the user manual

0 Likes

#3

For example, i have a dataset i have inserted an item code,the item code in a dataset should be unique,and i have inserted another item code ,the first inserted item code and the second item code is the same,how can i detect or stop adding the same item code in a dataset?

0 Likes

#4

If your data set if coming from a database table you can set the columns to be unique.

Another way and I use this method sometimes…

I assume the item code you enter is in a text box? Add a custom property to that text box. On the custom property do a count query based on how many times that item code appears. If it’s a 0 then it hasn’t been used. Anything 1 or greater shows that it has already been used.

Then on the button you press to enter your data into the dataset do something like… if “custom property” = 0 “add record script” else if custom property =>1 “open pop up window script”

You can make a generic error / warning pop up window. Have a custom parameter for the error message and when you want to pop up an error or warning just pass the error text In the open pop up script.

1 Like

#5

To help out a bit more. You can probably polish it up or even use a totally different way to check if a value already exists before updating a table / dataset

On the button you press to enter the information into the database…

	itemcode = your item code custom property
	message = Item code already exists	
	if itemcode == 0:
		system.db.runPrepUpdate("INSERT INTO........
	
	elif itemcode > 0:
		system.perspective.openPopup("xyz1234",'View/View', params = {'message':message}, modal = True, showcloseicon = False, resizable = False, Draggable = False)

:message is a input parameter on your pop up view.

On the text box that you enter the item code in have a custom property that runs a named query (mysql database).

Select COUNT(id)
From mytable
Where itemcode = :code

The :code parameter has to be linked to the item code text box .text

The named query will return a number, that number is the number of times that item code appears in your table column. If the result is 0, the database update is performed when you press the button otherwise if that value is greater then 0, a pop up opens with a warning message.

0 Likes