Configuring Comm Server Messages

Hide Topic ContentsShow Topic Contents
    1. Example Comm Service Stored Procedure

Use the Messages window to display and manage all comm server message types.

Select the Services tab.

Click Messages (). The following screen will appear.

Click the Add button () in the bottom left corner.

In the Description field enter a unique description to identify the message.

In the Queue Size field enter how many messages can be cached for monitoring purposes.

In the Procedure list you can specify a custom stored procedure to be executed when a message is received.

Only stored procedures that have a name starting with CUSTOM_ will be listed.

If required, click Import Fields. The fields required for the stored procedure will be added to the Fields section.

In the Fields section specify the labels that the message will contain.

Please note that Label keys are case sensitive.  If the Import Fields function is used, labels are imported in lower case.  Please ensure that the Label keys match the case found in the input file.

Click the Add button () in the Fields section to add a new label.

Enter a Description of the label (this doesn't have to be the actual label).

Enter a Label Key.

Click Save. The label is added to the list.

Click OK . The message is added.

Example Comm Service Stored Procedure

The example below details a stored procedure that can be used to return a custom error in Cockpit using a raiserror statement.

The stored procedure checks to see if the unit to be created already exists and if so, returns a custom error message that includes the Product ID and serial number provided to the stored procedure and sends it to the Comm Service.

/****** Object:  StoredProcedure [dbo].[custom_comsvs_create_new_unit]    Script Date: 9-3-2021 20:33:37 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

 

ALTER procedure [dbo].[custom_comsvs_create_new_unit]

   @productID   int,  

   @Serial      nvarchar(20)

as

begin

   set nocount on

 

   declare

         @unitID       int,

      @plantID    int,

      @buildGroup int,

         @modelyear  smallint,

      @prodDate   date,

         @serialno   nvarchar(20)

                 

   -- Get current date and use this for production date

   select@prodDate = getdate()

  

   -- Get default build group

   select@buildGroup = build_group_id

     from build_groups

    where is_default = 1

 

   -- Get default plant

   select@plantID =plant_id

     from plants

    where is_default = 1

 

   -- Get current model year

   select@modelyear = convert(smallint, datepart(yyyy, @prodDate))

 

   --Parse Serial

   if substring(@serial,1,2) = '??'

      begin

            select @serialno = substring(@serial,3,20)

      end

   else

      select@serialno = @serial

 

   -- Try to find unit

   select top 1 @unitID = unit_id

     from units

    where serial = @SerialNo

      and model_year = @modelyear

      and product_id = @productID

order by unit_id

 

   -- Quit if unit already exists

   if @unitID >= 1

      begin

            raiserror('ERROR: Unit already exists, Product_id = %d. Serial = %s.', 18, 1, @productID, @Serial) with log

         return

         end

 

   begin transaction

 

   -- Insert Unit

 

   insert into units

      (product_id, plant_id, model_year, serial, lot_id,

       build_group_id, prod_date, num_defects, num_unrepaired_defects, num_repaired_defects, num_confirmed_defects, is_locked)

   values

      (@productID, @plantID, @modelyear, @serialno,  null,

       @buildGroup,@prodDate, 0, 0, 0, 0, 0)

 

   set @unitID = scope_identity()

 

   -- Insert into Checklist Generation Queue to force checklist creation

   insert into chk_generation_queue

      (unit_id, is_force_create)

   values

      (@unitID, 1)

 

   --Insert value in unit_lookup_codes, in this demo database lookup_type_id 23 is used to indicate the unit was created by comm service

   insert into unit_lookup_codes (unit_id, lookup_type_id, lookup_code) values (@unitID, 23, 'Yes')

 

   commit

end

An example error message is shown below.

Can we improve this topic?