0
Answered

PowerShell transformation recalculation

Rizwan Ahmed 4 years ago updated by Matthew Davis (Technical Product Manager) 1 year ago 6

We have staff details sourced from Oracle table example fields are EmployeeNumber, StartDate and LastUpdated. The requirement is to activate the staff account seven days before the start date. We calculate the AccountStatus in a PowerShell transformation i.e. Active or Inactive based on the StartDate. UNIFYBroker is configured to run full import every hour.

For example, a new staff member is added into the source system on 20-Dec-2019; and after 20-Dec-2019 the record is not updated in the source system, below is the state. 

 

Staff Connector

Staff Adapter

EmployeeNumber = 123456

StartDate = 2-Jan-2020

LastUpdated = 20-Dec-2019

EmployeeNumber = 123456

StartDate = 2-Jan-2020

LastUpdated = 20-Dec-2019

AccountStatus = Inactive

As per the requirement staff should be enabled on 27-Dec-2019. On 2-Jan-2020 following was the state.

 
 

Staff Connector

Staff Adapter

EmployeeNumber = 123456

StartDate = 2-Jan-2020

LastUpdated = 20-Dec-2019

EmployeeNumber = 123456

StartDate = 2-Jan-2020

LastUpdated = 20-Dec-2019

AccountStatus = Inactive

However, when we execute Advanced Operations --> Generate Changes manually AccountStatus was updated to ‘Active’.

It appears that if there is no change to the connector entity the adapter’s PowerShell transformation is not recalculated even on connector's full import. 

Is there a workaround?

Answer

Answer
Answered

Powershell transformations now have the ability to register fields with change detection in the latest 5.3 release. 

Information on the capability is available on this ticket, documentation will be updated in the future to include proper usage of this capability:

https://unifyvoice.userecho.com/communities/6/topics/4238-time-offset-flag-didnt-re-evaluate-when-date-threshold-was-passed

Under review

Hey Rizwan,

PowerShell transformations don't participate in change detection. This means that when data is going through the adapter, if a change would result from the execution of the script but not elsewhere, (IE the input data is the same but the logic means the output would change) then the script won't execute in that scenario, because Broker doesn't know that the output would change. I believe that if another field on the entity changes, then all transformations for that user would be processed. 

A current workaround is to do a daily "Generate Changes" operation on the adapter. This can be called automatically through the REST API on certain UNIFYBroker versions.

I believe that the use case has been resolved by support in the past, although i'm not sure on the specifics. Might be worth reaching out to Richard or Bob and seeing how they've solved this previously.

Hi Matt and Riz.

I've only done this sort of thing for the Health Check and Safety Catch scripts in the past ... however they are ugly for the obvious reason of having to hard code guids/servers/ports:

[string]$brokerAdapterID = "<my adapter guid>"
[string]$brokerPort = "8008"
[string]$brokerServer = "<my url>"
[string]$uri = "http://{0}:{1}/Adapter/SimulateChanges/{2}" -f $brokerServer, $brokerPort, $brokerAdapterID
$wc = New-Object System.Net.WebClient
$wc.UseDefaultCredentials = $true
$response = $wc.DownloadString($uri)
$wc.Dispose()

However, while the above works OK and would suffice as a stop-gap, a far neater script would perhaps leverage the Invoke-RestMethod command, referencing the in-built REST API as per https://voice.unifysolutions.net/knowledge-bases/7/articles/2978-apis ... however I've only made had an initial foray so far.  Can I suggest, Riz, that you make some time with Matt to come up with a REST API alternative to the above?

P.S. A further update on the above - I browsed to http://localhost:59991/IdentityBroker/swagger and after I waited for Swagger to generate the complete doco for the default API (which I was able to work by looking at the guid in the URL for Settings/Default API), I was able to confirm that I could happily invoke methods like GetAllAdapters to allow me to find the guid for the one I wanted by name.  The rest of this should be straight-forward from here I think ...

I couldn't help myself - since I've been wanting this capability myself for ages ... here's my improved PS code using the REST API (Matt - please advise if you can see any obvious improvements?):

[string]$brokerPort = "59991"
[string]$brokerServer = "<my Broker server>"
[string]$uri = "http://{0}:{1}/IdentityBroker/api/1.0" -f $brokerServer, $brokerPort
[string]$adapterName = "<my Adapter name>"
# 1. Get adapter ID
$adapterURI = $uri + "/Adapter/GetAllAdapters"
$adapter = (Invoke-RestMethod -Uri $adapterURI -UseDefaultCredential -Method Get) | Where-Object {$_.AdapterName -eq $adapterName}
# 2. Generate Changes
$adapterChangesURI = $uri + "/Adapter/SimulateChanges?adapterId={0}" -f $adapter.AdapterId
Invoke-RestMethod -Uri $adapterChangesURI -UseDefaultCredential -Method Put | Out-Null 

Incidentally, Rizwan, the IsOperativeFlag transformation should give you what you want and allow you to avoid a PS adapter transform altogether - it did for me recently ...

Answer
Answered

Powershell transformations now have the ability to register fields with change detection in the latest 5.3 release. 

Information on the capability is available on this ticket, documentation will be updated in the future to include proper usage of this capability:

https://unifyvoice.userecho.com/communities/6/topics/4238-time-offset-flag-didnt-re-evaluate-when-date-threshold-was-passed