How to use activities that require a context inside a workflow

For the sake of organization and “code” readability, sometimes I want to move a certain piece of “code” (or workflow) inside its proper Workflow (like a function or method).

But this is sometimes impossible for me because the there are parts of the workflow that include activities that need to be “inside” a certain context activity (Office 365, Teams, Sharepoint an the like), thus being impossible to properly organize “code”.

Is there a way to overcome this that I’m not aware of?

Maybe it should be possible to pass the “context” as a variable to the Workflow so it’s available for the activities that are complaining of, or Studio should be “intelligent” enough that those activites are inside a Workflow that’s being called inside a “context” activity already and provide it to its internal activites.

Otherwise we end up with a lot of nested activities and worklow Does, Sequences and the like that, at a certain point, are impossible to manage.

The way you can achieve this is by using Extract As Workflow for the activities within the Excel Scope for example or anywhere you want to create modular logic.

In the below picture I have a Excel Scope → Excel File → and two Log Messages
Assume the three variables “ExcelFilePath”, “Message1”, and “Message2” were created in Main.xaml

Now lets say we want the have a dedicated workflow for Use Excel File activity within the Excel Scope, then you can use Extract as Workflow

This will tell UiPath to create an argument to pass the ExcelFilePath from the Main Sequence to a dedicated workflow (where your logic resides)

The invoked file would look like this

You can ignore the warning sign (yellow warning) as it will not fail at runtime. This is still not ideal according to me, but that is the best we can do.

Also notice that depending on where you use the “Extract as workflow” arguments will be generated. In the above case, Message1 and Message2 will continue to be variables as they were before within the “Use Excel File” activity in the main sequence.

Sample file :
ExtractasWorkflow.zip (156.4 KB)

Pro tip:
Always best to design you logic outside studio and create modular workflows, which can easily be used in other projects saving a lot of development time. We use UML diagrams to design our processes first then convert them to UiPath workflows. Making the entire project modular and reuseable. Much like SOLID ( SOLID: The First 5 Principles of Object Oriented Design | DigitalOcean)

Cutting down a long workflow using Extract as Workflow will be time consuming during development, testing and a pain to troubleshoot in production.

Thank you for your reply,

The solution you proposed works for Excel in these activities because the package provides a way to get access to the context.

In fact, what I was asking was a way to do something like that in activities that don’t provide this reference, as the ones I mentioned. Specifically, the SharePoint one.

Apart from that, in the case of my workflow it’s very difficult, or poorly efficient, to decouple it in a way that I can use it within the scope of this SharePoint activities. Thanks for the recommendation about the “SOLID” principles and the conseiling about proper object oriented design, but having studied it decades ago during my college years and having some other decades of exprience as a computer analyst, I don’t think reminding that belongs it’s out of the scope of this thread.

Using the “Extract as Workflow” tool is straightforward, but unfortunately it’s not working for the kind of activities I mentioned in the original question, as I explicitly explained that they don’t provide a way to get access to the “context”. That’s why I’m asking about ideas/alternative ways of accomplishing it.