Skip to main content
TOPICS

CATEGORY

PUBLISHED
25 March 2022

MODIFIED
28 September 2024

Sample Python Scripts

Below are a couple of sample Python scripts that can be used in CardExchange Producer.

These make use of the Functions tab available in the Enterprise edition, for the Business edition and for simple scripts, you can directly use the script box in the content tab of the item properties.

# *** imports ***

import datetime

# *** designer functions ***
Now = datetime.datetime.now()
Date = Now.date()
plus1year = datetime.timedelta(days=365)

def datetostr(Date):

return str(Date)

def expirydate(expiry):
expiry = Now + plus1year
return str(datetime.date.strftime(expiry, "%d/%m/%Y"))

def issueno(i):

if i == "":

return "1"

else:

issue = int(i) +1

return str(issue)

The above functions can be copied into the functions tab so that they can be called by any script.

SPS 1

Python scripts are always working with variables instead of directly with the Database columns or other information, so you will need to create variables and map them to the desired database columns if required.

This can be done by selecting the variable from the data tab on the left of the designer and choosing the mapping from the dropdown, or by selecting the variables tab in the properties window and dragging the database column into the content box next to the variable name.

The green outline indicates that the variable is mapped to a database column.

SPS 2

To call a function, you simple select the desired object, which could be a visible item or a storage item for example. Then under the content tab in the properties window you can choose the script option and enter the name of the function.

The below script shows an example of how to increment an issue number before printing to ensure that the next value is printed on the card correctly:

SPS 3

This example does not use any database columns, instead it takes the current Date and adds one year to it

to give us an expiry date:

SPS 4

You can also enter simple scripts directly into the script box, for example you could create two variables

linked to the first name and last name of a person.

SPS 5

Then you can create your own concatenation source but adding the desired variables.

SPS 6

Using this method, you could add custom separators between the variables as below:

SPS 7