Creating Scripts

Hide Topic ContentsShow Topic Contents
  1. What are Scripts?
  2. Create a Script
  3. Defining Tag-Based Scripts
  4. Defining Dynamic Scripts
  5. ATS Bus Scripts
  6. Script Examples

What are Scripts?

Update script info

Scripts contain the instructions for displaying the text in the notification. These instructions include the "boilerplate" text (the fixed text that doesn't change) and the field name, which supplies the data that you want to include in the notification. You can create your own scripts or edit existing scripts.

Because different notification systems (email, video wall) display different amounts and formats of text, you will need a different script for each of the ways you send notifications.

Developing scripts requires a solid understanding of databases and script programming. In most facilities, the IT department is responsible for developing scripts. If you have special scripting needs, be sure to work with the correct resources in your organisation.

Create a Script

Select the Services tab.

Click Scripts.

The Scripts window opens.

Select an Event Type from the drop-down list to specify which type of event to create.

Click the Add button ().

The Event Script wizard opens.

Enter a name for the script In the Description field.

Select whether the script is Dynamic or Tag-based.

The Valid checkbox, adjacent to the Script Type drop down box, indicates the validity of a script.  
When editing a script, the checkbox is ticked if the script was run successfully and without errors. 
When creating a new script, the checkbox is ticked by default.
If the script is run and results in an error, the checkbox is blank when the script is edited.

What's the Valid checkbox for?

Enable the Active checkbox to make this script active.

Click Next.

Enter the required script as described below.  A sample output can be generated in the Script Output pane by pressing the Run button.  

Click OK.

The script is saved.

Defining Tag-Based Scripts

Tags are dynamic fields that are populated with the correct information when the message is created. Tag-based scripts are created by typing in the standard text you want and then dragging and dropping tags where needed. Tags have a "~" at each end.

For example, the following text could be used for a defect event script:

~Defect.Concern~ on ~Defect.Location~ ~Defect.Part~ was entered at ~Defect.Station~ on unit ~Unit.Identifier(SERIAL)~.

Rank: ~Defect.Rank~

Time: ~Defect.ActualHour~

This could produce a message for the recipient like the following:

Scratch on Top Strap was entered at Assembly1 on unit 001323

Rank: Low

Time: 12:25

Defining Dynamic Scripts

Dynamic scripts are written in C#.

Below is a very simple example of some code that will return a list of products:

// Header

WriteLine("Product Listing");

WriteLine("Id    Code");

 

string connectString = @"Provider=SQLNCLI10;Data Source=DATABASESERVER;Database=Inspect;User Id=sa;Password=master;";

 

try

{

   using (var sql = new AdoSql(connectString))

   {

      sql.SetCommand("select product_id, code from products order by code", ATS.Shared.ADO.NET.CommandType.Text);

 

      if (sql.OpenDataset())

      {

         while (sql.Read())

         {

            int id;

            string code;

 

            sql.GetField(0, out id);

            sql.GetField(1, out code);

 

            WriteLine(string.Format("code = {1}, id = {0}", id, code));

         }

      }

 

      sql.CloseDataset();

   }

}

catch (Exception ex)

{

   WriteLine(ex.Message);

}

This could produce the following output as an example:

Product Listing
Id Code
code = AIRBAG, id = 164
code = AIRPLANE, id = 74
code = APPLES TRAY, id = 106
code = AUTO-(3D), id = 5
code = BEER BOTTLE, id = 107
code = BOAT, id = 8
code = BODY-IN-WHITE-(3D), id = 143

ATS Bus Scripts

Inspect can output data directly to ATS Bus.  Follow the below steps to output data using a dynamic script.

Create an ATS Bus output. For details, see here.

Create a Recipient. For details, see here.

Create a dynamic script using the following code:

WriteXml();

Use the script for a new trigger and specify the recipient created in the step above.  For details on creating Trigger events, please refer to the examples in the Creating Trigger Events menu.

Script Examples

The following script examples are available:

Tag Based Script Examples

ATS Bus Script

Checklist Question Answered Event

Defect - Quantity per Time Event

Defect - Quantity per Units Event

Defect Event

Export - Defect Event

Export - Inspection Event

Export - Repair Event

Inspect Completed Event

Repair Event

Special Output

Tracking - Defect Check Event

Tracking - Good Unit Mix Event

Tracking Event

Dynamic Script Examples

Embed custom tags in XML output

Get list of part ID and code values using ADO.NET

Get station id and area id for station code using ADO.NET

Lookup unit info based upon XML Tag

Can we improve this topic?