Custom Script Running Twice Even if Process is triggered once

I am integrating Oracle Cloud HRMS as trusted source with ONE Identity Manager using REST APIs. 

I have written custom script which calls get all users API and stores the employee records in CCC_StagingPerson (extended Schema table in One Identity Manager Database)

When I run the script via Designer -> process automation -> Run -> triggers Process -> Calls Script 

Here is the first problem, if process is triggered once - script should also be executed once, but in logs I can see script is executing twice.

The first time script gets executed fine until API call, parsing response and printing response successfully and then throws exception, 

Object reference not set to an instance of the object.

 After printing response, code checks whether employee record exists in CCCStagingTable or not using below code to take next actions.

       1. Dim f As ISqlFormatter = Connection.SqlFormatter

  2. Dim Where As String = f.Comparison("CCC_employeeID", employeeID, ValType.String)

  3. Dim dbPerson = Session.Source.Exists("CCCStagingPerson", Where )

 On the third line I am getting above exception as confirmed in the logs.

 Weirdly, script gets executed second time immediately after the exception and this time no exception is thrown.

 
Can anyone please suggest, what could be main root cause.

First problem, --> even when process is triggered once, how does the script gets executed twice.

Second problem --> Script always throw exception on this line of code, irrespective whether I use Session.Source.Exists/GetSingleValue - Dim dbPerson = Session.Source.Exists("CCCStagingPerson", Where )

Third problem --> When I run the sync project to sync employee records from CCCStagingTable into person table, it still executes the custom script and it throws same exception once.

 Appreciate any support to resolve the same.