cancel
Showing results for 
Search instead for 
Did you mean: 

Attach in the Initialise action

JakobSørensen
Level 4
Our team is discussing where to put the attach logic which is required for business objects, which uses an existing browser session.

One of the ideas is to put the attach logic in the 'Initialise' action, which exists in all business objects. Of course it would check if it was already connected, before trying to attach. You can see the detail in the screenshot below.

Is this the correct approach (assuming that there is one single correct approach)? I haven't really been able to find any best practices on how and when to attach.


23160.png

------------------------------
Jakob Sørensen
------------------------------
8 REPLIES 8

Hi @Jakob Sørensen

Almost, in my case I prefer to put in the "Initialise" page only the Global Variables and Global Code for the VBO.

And have another page to check if is connected and if not, try to attach it. Similar to your page, but, important, captures the error that may occur in the "Attach" action with a Recover stage.

I think all approach are correct in this way, it's depend on your solution architecture. Let see what other Community Member think about this


See you in the Community, bye 😄

------------------------------
Pablo Sarabia
Architect
Altamira Assets Management
Madrid
------------------------------

DaveMorris
Level 14
Hi Jakob,

I feel like you or someone else brought this up a year ago or so, and I found it an interesting idea then as well. Doing things this way does kind of make intuitive sense, but I think in practice, it would end up with unexpected results. This next sentence or two may not be true for all Blue Prism versions, but I believe it is still true. Blue Prism object instances that are called directly by the running process are instantiated at the moment the session starts, not when one of its actions are run, so I believe that would mean the app you want to attach to has to already be open before the Blue Prism session begins. It works like a Constructor, meaning that it will only ever run once for that Object instance which also means that failures cannot be retried for this, and you would still need an Attach page to handle attempting to attach to the app again upon a retry. Have you tested this? I feel like it might not work, but I mean if it's working for you then I would be interested in looking into it more.

One standard practice for when to attach is to have an unpublished Attach page and then subpage references to that Attach page at the beginning of every single published Action. Most of the time this means the Attach page is run and nothing happens because it's already attached, but this also helps with debugging when you want to open an Object and run a quick test. This would cause it to attach to the running instance of your app for the debug test.

So, just thinking through this, wouldn't your Initialise page throw an error when your session starts and the app hasn't been opened yet? Another thought here is that you possibly could see different results depending on how nested your action calls are. I'm not sure 100%, but I think Blue Prism may not instantiate all object instances that are nested until they are called initially. I need to test this stuff again because things may have changed.


------------------------------
Dave Morris
3Ci at Southern Company
Atlanta, GA
------------------------------
Dave Morris 3Ci at Southern Company Atlanta, GA

It was a part of an earlier post of mine, but back then the question was whether 'Attach' should be called explicitely from the process or implicitely inside the actions. We landed on the ladder. So I guess you can say this post is the next step of the discussion :-).

I am not 100% sure, but from what I have seen so far, it seems that the 'Initialise' action is called the first time an action on the object is called. This would also be similar to a constructor (in traditional programming) which is called upon the first initilisation of the class.

If it does cause issues, my 2nd choice would be an attach page which is called in the beginning of each action. But I really don't get what the 'Initialise' action is for, if that is the case (yes you can use it for global variables, but why would that need to be an action?).

------------------------------
Jakob Sørensen
------------------------------

Sure enough, you're right. The object instance isn't created until the first action of the object is called. I wonder if Blue Prism changed when objects are instantiated in one of the versions, and I didn't notice. In any case, yeah I just tested it, and the Initialise page is not run when the session starts and instead runs when the first action starts from that object.

I do think it's still going to be a good idea to have an attach subpage reference at the beginning of each action for situations where the app gets closed and reopened during retries because that would cause the object to be not connected anymore, but it wouldn't reattach because the Initialise page won't run again. Have you run into this issue?


------------------------------
Dave Morris
3Ci at Southern Company
Atlanta, GA
------------------------------
Dave Morris 3Ci at Southern Company Atlanta, GA

That's a very good point. I haven't yet seen any issues where it restarted the browser and there by lost connection. But I would expect that you are right. 

I made a test where I log initialise and an action via notes. The action on the object is called three times on two different pages. It appears that Initialise happens when the first action starts and Clean Up happens once the last action ends.

23153.png

------------------------------
Jakob Sørensen
------------------------------

John__Carter
Staff
Staff
Hi Guys

The Initialise page has always been executed at the moment the first action is called, not when the process starts. Cleanup is executed when the process ends.

One downside of attaching on the Initialise page is that it makes it awkward to attach when in Studio. Otherwise I don't mind if people use explicit or implicit calls, but personally I prefer to publish an Attach page and call it explicitly. I've always found the 'attach at the start of each page' somewhat unnecessary and sometimes even counter productive, similar in a way to the 'try everything 3 times, just in case' approach you often see.

------------------------------
John Carter
Professional Services
Blue Prism
------------------------------

Thanks for the clarification, John. Do you happen to know the answer to Dave's question? That is, what happens if you attach in the Initialise action but then have to re-start the browser due to a crash? Will the attachment then be lost for the session, as Initialise will never be run again (in that session)?

------------------------------
Jakob Sørensen
------------------------------

Hi Jakob - if the target app closes normally or crashes, then the object will become detached (because the app has gone). If the process session is still running, then the Initialise page has already been executed and will not run again. So if the VBO is not the one who will relaunch the app (and therefore become attached again) then it will need to explicitly attach to the new instance of the app.

------------------------------
John Carter
Professional Services
Blue Prism
------------------------------