another technical blog...technically

Monday, April 22, 2019

Anatomy of a BP consumer template

After a lot of work, Antonio Durante and I decided to create a template to standardize someway how we build consumer processes in Blue Prism.
So let me introduce you DaTemplate.

DaTemplate overview
This is the consumer roundtrip for a typical process that works with queues: i use it everytime.
The concept is, raise exception alwais to the hightest level.

Let's examine the right part first.
After start i reference two pages:
  1. Reset: no matter what happened, close every application that can someway create problems to out process;
  2. Config: configure the environment if needed and get the process global variables
Then i start with the get next, but i put all the data item data in global variables, so they are accessible everywhere. No more global variables except item one and config one, all other variables must be local to the page they are declared in.
In the end i call a page "Item Logic" which is typical of the process.

The right part

So in the process pages, you will use recover resume block to manage exceptions, but, if the result is BusinessException/Managed Exception or Technical Exception, don't do anything and let the left part of the template work for you.
The exception message is extracted and the right action addressed according to exception type.
If Business or Managed Exception, item will be Mark Success (i consider a recognized exception as a success only in the technical log), and logged as an exception in the business log.
If the exception is unknown or a technical one, the process for that item will be repeated for MaxAttemps times before becaming a Managed exception.
Error is screenshotted for further investigations.

The left part for managing exceptions
Please note that on get next and Check Attempts there is a recover resume block.
This is due to the potential failure of the get next, and also a potential failure in the left part of the template that could create an infinite loop.
If we got an unexptected exception, those recover resume blocks will take the template to a new get next operation, just taking 5 seconds to breath (in the case of get next failure).

That's all folks, i hope you find it useful

Monday, April 15, 2019

BP and JSON

As you already know, BP works on queues.

What if a process is not based on queue items but is based on a sequence of bulk operations?
You can think every bulk operation as fake queue item and manage them from control room.
But maybe you want to apply some logic, for example, let's assume your process id made of 4 subprocesses (A, B, C, D), if something go wrong with A you don't want to execute C, no problem on B and D.

Yeah, maybe too simple as an example, but use you imagination... believe me, you don't want to know anything about the process that, in the real world, lives on this solution (Alberto Cannas became mad on this).
So think about a process that doesn't rely on queue and where you want to play with subprocesses that can be seen as transactions.

We could store the data in a DB, but what if we cannot use a DB... we can use a JSON file as a DB, in order to have a flexible DB that helps us.
For example, in the process we are dealing with, we use a JSON file that is generated everyday, and the process state is represented by data in a collection.

I will show you a little process that simply export data only at 10.00/12.00/14.00/16.00 using JSON  to make all clear. This is what BP object Utility - JSON wrote when using Collection to JSON action.

{"Log 10":false, "Log 12":false, "Log 14":false, "Log 16":false} 

So you can read the informations you store in your information in a JSON file, implement your logic, and write again only when needed.
You should take care about 2 things:
  1. The subprocess that works on file must be encapsulated in enviroment lock. This will be helpful in a multi-robot environment;
  2. Pay attention to what you write in the JSON, when you use JSON to Collection action, the objects write the collection as an array, so you have to remove brackets at beginning and at the end of the JSON (thank Manuel Mascia for the trick)
Yeah... tips'n'tricks

Now you can push this solution beyond this example.
That's all folks.

Monday, April 8, 2019

BP and Angular

Working with Antonio (Durante ndr), we faced a problem automating modern web application written in Angular.
Let me explain you the scenario, we spied all the textboxes with HTML spy mode and we wrote values into the textboxes, but the system returned an error.
I cannot show you anything else because... come on you know why, but focus on the red border and trust me that the message showed by the system is: please enter a value.

And the system said: please enter a value

Why this happened?
Simply because, even if we wrote something, the ng-pristine tag is still here.
What is ng-pristine? A tag that tells the model that no fields has been modified.

How to solve this problem? Convince Angular you did something on the interface.
In the example below, we wrote the value 7200 in the field with name agenziaOrdinante.
After that we force angular to call the change event and then the blur event, in this way we notify to the model that something has changed, with the blur event indeed we are sure to trigger other potential events that are fired when we click elsewhere.

JS = lifesaver
In the end mind to create a VBO that writes data using JS to generate and launch the javascripts one by one.
Instead of ElementName input, in the final version i preferred to use JS selector as input to make the code more generic.

Write data action example
And that's all folks. As usual thanks to Antonio Durante for the fun trip.

Monday, April 1, 2019

Add credentials from BP... programmatically

As you know, you can use BP not also for automate business processes.
For example, in our scenario (we are talking about a RPA program with more than 30 complex automations), we have credentials that expire if you don't login with those credentials for a certain period of time.
On the other hand, because of, every time we provision a new process, we have to add to credential manager, all the credential needed by the process itself (call this value x) for all the machines involved (call this value y), it's easy to understand that the process of provisioning and keeping credentials alive led me to a new limit: BP does not provide anything to create credentials, so SQL is out ally.
So the key is to launch someway (ODBC or whatever) this custom SQL store procedure from BP.
The result will be a credentials with all roles, with permissions on all processes and resource PCs and with a void password.
Please note that void is 3uDCB67zyUqBsHym7o635w==:JM6brcdYVFsZhbEKISRtaQ== for BP since because the value is encoded and may vary depending on Encryption Scheme so make sure you already check what is the null password value on your farm.

Add credentials script

USE [BluePrism]
GO
/****** Object:  StoredProcedure [dbo].[BPAddUser]    Script Date: 04/10/2018 14:45:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[BPAddUser]
       @userLogin nvarchar(128)
AS
BEGIN
       -- SET NOCOUNT ON added to prevent extra result sets from
       -- interfering with SELECT statements.
       SET NOCOUNT ON;

    -- Insert statements for procedure here
       BEGIN 

             if not exists (select * from BPACredentials where login = @userLogin AND name = @userlogin)
                    BEGIN
                           declare @newid uniqueidentifier = NEWID();

                           INSERT INTO [dbo].[BPACredentials]
                                  ([id],[name],[description],[login],[password],[expirydate],[invalid],[encryptid])
                           VALUES
                           (@newid,@userLogin,'Created by script',@userLogin,'3uDCB67zyUqBsHym7o635w==:JM6brcdYVFsZhbEKISRtaQ==',NULL,0,1)

                           INSERT INTO [dbo].[BPACredentialRole]
                                  ([credentialid],[userroleid])
                           VALUES
                                  (@newid, NULL)

                           INSERT INTO [dbo].[BPACredentialsProcesses]
                                  ([credentialid],[processid])
                           VALUES
                                  (@newid, NULL)

                           INSERT INTO [dbo].[BPACredentialsResources]
                                  ([credentialid],[resourceid])
                           VALUES
                                  (@newid, NULL)
                    END
             Else
                    BEGIN
                    
                    DECLARE @credentialId uniqueidentifier;
                    select @credentialId = id from BPACredentials where login = @userLogin AND name = @userlogin;
                    
                    -- Create or overwrite 
                    if not exists (select * from BPACredentialRole where credentialid = @credentialId)
                           INSERT INTO BPACredentialRole([credentialid],[userroleid]) values (@credentialId, NULL)
                    else
                           update BPACredentialRole set userroleid = NULL where credentialid = @credentialId
                           

                    -- Create or overwrite 
                    if not exists (select * from BPACredentialsProcesses where credentialid = @credentialId)
                           INSERT INTO BPACredentialsProcesses([credentialid],[processid]) values (@credentialId, NULL)
                    else
                           update BPACredentialsProcesses set processid = NULL where credentialid = @credentialId


                    -- Create or overwrite
                    if not exists (select * from BPACredentialsResources where credentialid = @credentialId)
                           INSERT INTO BPACredentialsResources([credentialid],[resourceid]) values (@credentialId, NULL)
                    else
                           update BPACredentialsResources set resourceid = NULL where credentialid = @credentialId
             END

       END
END
Share:

Me, myself and I

My Photo
I'm just another IT guy sharing his knowledge with all of you out there.
Wanna know more?