/
IFS ProCount Workflow Invoker

IFS ProCount Workflow Invoker

Search the IFS Workflow Wiki
 

Back to Tips and Tricks

 

Introduction

A new IFS ProCount service was created for the Ascend demo.  This service is called Ascend.ProCount.Workflow.Invoker and monitors a table in the IFS ProCount database. It calls the workflow API end points for each entry in the queue table. To configure the process, configure the inputs through the settings in the application's config file, or modify the trigger and queue table.

 

IFS ProCount Workflow Invoker.png

 

Configuring the Service

Configuring the Service

Stop the Service

The service is listed in the services panel.  While getting things set up, it is recommended that you stop the service and run the invoker manually until the process runs as you expect it to. Once working, you can then start the service and have it check the queue table in increments of seconds.

To stop and disable a Service in Windows:

  1. Click Start, click All Programs, click Administrative Tools, and then click Services.

  2. In the right-hand pane of Services, locate and double-click the Ascend.ProCount.Workflow.Invoker service.

  3. To stop the service, click Stop.

  4. Change the value for Startup type to Disabled.

  5. Click OK to save the changes.

Edit the Config File

Settings in this file control the calls to the workflow API along with the connection to the IFS ProCount database.

To edit the configuration file:

  1. Find the following file: P2Ascend.Workflow.Demo.Service.exe.config

  2. To open the file for editing, use a text editor.

  3. Add the following code to the file, replacing the values in red with your own settings:

<add key="SecondsBetweenPolls" value="30"/>

<add key="QueueTables" value="YourWorkflowQueueTb"/>

<add key="WorkflowURL" value="http://URL/"/>

<add key="AuthenticationPath" value="P2Demo/oauth2/token" />

<add key="CasePath" value="api/1.0/P2Demo/cases/impersonate"/>

<add key="RoutePath" value="api/1.0/P2Demo/cases/{appUid}/route-case"/>

<add key="ClientID" value="OBIQPBRYIUULZRPETBXIZMZYVXTWZFAO" />

<add key="ClientSecret" value="265187711598a502a8c9801057412853" />

<add key="UserName" value="AdminUser" />

<add key="Password" value="password" />

<add key="ProUID" value="12734012059ee6159991057027054023" />

<add key="UsrUID" value="8174230295988dd40f14f33060600180" />

<add key="TasUID" value="63639893459ee64b4569ed4072281864" />

                <connectionStrings>

                                <add name="ProCount" connectionString="Server=MyServer;Database=Procount;User ID=adminuser;Password=password;Provider=SQLOLEDB"/>

                </connectionStrings>

Configure the Queue Tables

When posting the case to the workflow API, the variables section of the post is derived from the columns of the queue table. 

A queue table must have the first 3 columns: 

  • Id (a sequence to be used as the primary key)

  • UpdateTime (the time that the record was inserted, just for debugging purposes)

  • WorkflowInvoked (a flag that indicates that the workflow was invoked.  Set to 1 by the “invoker”)

The rest of the columns are optional and will be passed as variables to the case. 

SAMPLE TABLE

The following table is a working example being used for the queue:

CREATE TABLE [DemoWorkflowQueueTb](

          [Id] [int] IDENTITY(1,1) NOT NULL,

          [UpdateTime] [datetime] NULL,

          [WorkflowInvoked] [int] NULL,

          [MerrickID] [int] NULL,

          [DateOfFirstProduction] [datetime] NULL,

 CONSTRAINT [PK_DemoWorkflowQueueTb] PRIMARY KEY CLUSTERED

(

          [Id] ASC

))

GO

ALTER TABLE [dbo].[DemoWorkflowQueueTb] ADD  CONSTRAINT [DF_DemoWorkflowQueueTb_UpdateTime]  DEFAULT (getdate()) FOR [UpdateTime]

ALTER TABLE [dbo].[DemoWorkflowQueueTb] ADD  CONSTRAINT [DF_DemoWorkflowQueueTb_WorkflowInvoked]  DEFAULT ((0)) FOR [WorkflowInvoked]

GO

In the working example, the trigger inserts MerrickID and DateOfFirstProduction into the queue table.  The invoker service examines the structure of the table and passes variables for any column other than Id, UpdateTime, and WorflowInvokde.

CREATE OR ALTER TRIGGER DemoWorkflowFirstProduction

ON CompletionTb

AFTER UPDATE, INSERT

AS BEGIN

    …

          Insert into DemoWorkflowQueueTb (MerrickID, DateOfFirstProduction)

          Values (@mid, @firstProduction)




Walkthrough

Walkthrough

Stop the Service

To allow a methodical step-through of this process, it is recommended that the service is not running.  To test the steps, you can run this service manually.  At the end of this walkthrough the service will be turned back on so that the workflow is invoked automatically.

To stop and disable a Service in Windows:

  1. Click Start, click All Programs, click Administrative Tools, and then click Services.

  2. In the right-hand pane of Services, locate and double-click the Ascend.ProCount.Workflow.Invoker service.

  3. To stop the service, click Stop.

  4. Change the value for Startup type to Disabled.

  5. Click OK to save the changes.

Review the Sample Queue Table

In the preceding configuration steps, a table was created to hold a queue of records which will invoke the workflow API. In this walkthrough we will use an example table name of DemoWorkflowQueueTb.

This table can be named anything as long as the invoker has the table name in its config settings file.

The config file exists in a directory similar to the following:

C:\AscendWorkflowInvoker\ P2.Ascend.Workflow.Demo.Service.exe.config on DDEMOPRO1

The table name must have an entry in this file similar to the following:

<add key="QueueTables" value="DemoWorkflowQueueTb"/>

Review the Sample Trigger

IFS ProCount uses the following dates for:

  • initial gas production

  • initial oil production attribute on a well completion 

This trigger figures out which of those dates occurs first and passes it to the DemoWorkflowQueueTb table.

The following code is for a trigger that populates the queue table:

CREATE OR ALTER TRIGGER DemoWorkflowFirstProduction

ON CompletionTb

AFTER UPDATE, INSERT

AS BEGIN

    SET NOCOUNT ON;

          Declare @mid int

          DECLARE @noDate datetime

          --instead of using nulls, P2 ProCount defaults to 1900 for no entry... if the date is > 1901 then it must be an actual entry.

          DECLARE @firstGas datetime

          DECLARE @firstOil datetime

          DECLARE @firstProduction datetime --will be set to the earlier of first gas or first oil

          set @noDate = '19000101' 

          set @firstProduction = @noDate;

          Select @firstGas = DateOfInitialProductionGas, @firstOil = DateOfInitialProductionOil, @mid = MerrickID from INSERTED

         

          IF EXISTS (SELECT * FROM DELETED)  --if deleted exists, then it's an update

                   BEGIN

                             --if the user has updated one of the intitial production fields, figure out which is first, gas or oil and queue a workflow

                             IF UPDATE (DateOfInitialProductionGas) OR UPDATE (DateOfInitialProductionOil)

                             BEGIN

                                      set @firstProduction = @firstGas;

                                      IF ((@firstOil < @firstGas AND @firstOil > @noDate) OR  @firstGas = @noDate)

                                      BEGIN

                                                set @firstProduction = @firstOil;

                                      END

                             END

                   END

          ELSE

                   BEGIN

                             --if the user has added a new completion with the initial production fields filled in, then insert a record in the queue

                             BEGIN

                                      set @firstProduction = @firstGas;

                                      IF ((@firstOil < @firstGas AND @firstOil > @noDate) OR  @firstGas = @noDate)

                                      BEGIN

                                                set @firstProduction = @firstOil;

                                      END

                             END

                   END

          IF (@firstProduction > @noDate)  --if firstProduction was set above then insert a row in the queue table

                   BEGIN

                                      Insert into DemoWorkflowQueueTb (MerrickID, DateOfFirstProduction)

                                      Values (@mid, @firstProduction)

                   END

END

Test an Update Made in IFS ProCount

To manually test the Workflow Invoker service, you need to make an update and manually run the service. Then you can review the queue table to verify the updates.

To test an update:

  1. In IFS ProCount, make any kind of edit on the Basic screen for a completion.

  2. To show the output from the trigger, query the queue table. For example, in SQLQUery, type select * from DemoWorkflowQueueTb.  Notice that WorkflowInvoked is currently 0.

  3. To invoke the workflow API, find the directory where the service was installed. For example, C:\AscendWorkflowInvoker.   Along with the service there is a command line application called TestInvoke.exe that can invoke the process once.

  4. To check the queue table and call the web service for any records found in the queue, run TestInvoke.exe. You should see a screen similar to the following:

If everything completes successfully, the queue table will be updated and WorkflowInvoked will be set to 1.

You can query the queue table again to verify this. For example, in SQLQUery, type select * from DemoWorkflowQueueTb .  

Start the Service

Before starting the service again make sure you have tested and found no errors with the following tasks:

The trigger is populating the correct table
The populated data is correct

If you encounter any issues while testing, remember that the settings the config file are what allows the invoker to send the data to the API. To troubleshoot issues, review the configuration file as described in the first section of this page.

The service does exactly what the TestInvoke.exe program does. The only difference is that the TestInvoke application only runs once. Before starting the service, you need to make sure that the configuration file has setting that you want to use in production. This may include adjusting the table name and setting how often the service checks, in seconds, for updates. Checking for updates is in the SecondsBetweenPolls setting.

To edit the configuration file:

  1. Find the following file: P2Ascend.Workflow.Demo.Service.exe.config

  2. To open the file for editing, use a text editor.

  3. Add the following code to the file, replacing the values in red with your own settings:

<add key="SecondsBetweenPolls" value="30"/>

<add key="QueueTables" value="YourWorkflowQueueTb"/>

<add key="WorkflowURL" value="http://URL/"/>

<add key="AuthenticationPath" value="P2Demo/oauth2/token" />

<add key="CasePath" value="api/1.0/P2Demo/cases/impersonate"/>

<add key="RoutePath" value="api/1.0/P2Demo/cases/{appUid}/route-case"/>

<add key="ClientID" value="OBIQPBRYIUULZRPETBXIZMZYVXTWZFAO" />

<add key="ClientSecret" value="265187711598a502a8c9801057412853" />

<add key="UserName" value="AdminUser" />

<add key="Password" value="password" />

<add key="ProUID" value="12734012059ee6159991057027054023" />

<add key="UsrUID" value="8174230295988dd40f14f33060600180" />

<add key="TasUID" value="63639893459ee64b4569ed4072281864" />

                <connectionStrings>

                                <add name="ProCount" connectionString="Server=MyServer;Database=Procount;User ID=adminuser;Password=password;Provider=SQLOLEDB"/>

                </connectionStrings>

To start and enable a Service in Windows:

  1. Click Start, click All Programs, click Administrative Tools, and then click Services.

  2. In the right-hand pane of Services, locate and double-click the Ascend.ProCount.Workflow.Invoker service.

  3. To start the service, click Start.

  4. Change the value for Startup type to Enabled.

  5. Click OK to save the changes.

Monitor the Logs

Use the WorkflowDemo.log file to observe how the service is working and to watch for potential issues or errors.

To monitor service calls and watch for errors:

  1. Find the following file: WorkflowDemo.log file. For example, it might be located in C:\AscendWorkflowInvoker

  2. To review the file, open it with any text editor.






Copyright© 2024 IFS AB. Copying prohibited. All rights reserved.