How to create Activity in Invoke Code with Output argument?

I tried doing this…

        Variable myBrowserVariable =
            Variable.Create("myBrowserVariable", typeof(Browser), VariableModifiers.Mapped);

        OpenBrowser samsungPortalBrowser = new OpenBrowser();
        samsungPortalBrowser.NewSession = true;
        samsungPortalBrowser.BrowserType = BrowserType.Chrome;
        samsungPortalBrowser.Url = "www.youtube.com";
        samsungPortalBrowser.UiBrowser = myBrowserVariable;

And then I invoked the workflow with a created sequence…

        Sequence createSequence = new Sequence();
        createSequence.Activities.Add(samsungPortalBrowser);

        try
        {
            createSequence.Variables.Add(myBrowserVariable);
        }
        catch (Exception ef)
        {

        }

        WorkflowApplication newWorkflowApplication = new WorkflowApplication(createSequence);
        newWorkflowApplication.Run();

But my output argument is not updated with the browser… anyone know what I’m doing wrong?

1 Like

Hey @Steve_Krozer

Can you please help us understand what’s the purpose of doing this way ?

Thanks
#nK

I actually found a way to port the libraries to visual studio, and when I write this code there and run the workflow, I can run as many workflows I can with the Workflow Foundation package.

What this means:

  1. I can write UiPath activities in C# code and work with my mates on github on the same project.
  2. I can add easily readable comments, code, variables and so on, studio is a fucking mess.
  3. You can run each workflow on a different thread, so not only you can run as many workflows as you want at the same time, but you can tie them to a different CPU thread.

Hi

Method1:

Create libraries for that. Publish to your local machine->Custom this will save in .NUPKG Format.

You can directly send this NUPKG with your mates.

Method2: (GIT)

  1. You can use version controls to commit the project which you’ve bulit in your studio.
  2. Give the access to your mates. They can also pull, push or commit the code. By using Control versions

Regards,
NaNi

I wish my opening post gets answered :(.

1 Like

What’s that sorry ?

I mean, how to write the code properly so I can add an outarguments that gets returned properly.

In the current context, no value is returned and the variable remains the same as it was when it was first initialized, trying to initialize the Expression with a New OutArgument of T along with the Result property of the Expression to add the OutArgument of T will do nothing because it says because it was already added to the UiBrowser, you cannot use it in the Result, which is weird.

With all the odds stacked against me, no one knowing how to answer a coding question on Stackoverflow, C# discord, RPA Discord or UiPath forums I have found the solution to the problem, lo and behold the method to get strongly returned types from UiPath activities!

internal class Program
{
static void Main(string args)
{
IDictionary<string, object> input = new Dictionary<string, object>();
input.Add(“inMSG”, “www.youtube.com”);
//input.Add(“myBrowser”, null);

        IDictionary<string, object> output = new Dictionary<string, object>();

        MyCodeWorkflow activity = new MyCodeWorkflow();
        output = WorkflowInvoker.Invoke(activity, input);
        //wtf
    }

    public class MyCodeWorkflow : Activity
    {
        public InArgument<String> inMSG { get; set; }
        public OutArgument<String> outMSG { get; set; }

        public OutArgument<Browser> myBrowser { get; set; }

        public MyCodeWorkflow()
        {
            this.Implementation = () => new Sequence
            {
                Activities =
                {
                    new OpenBrowser()
                    {
                        BrowserType = BrowserType.Chrome,
                        NewSession = true,
                        Url = new InArgument<string>((activityContext)=>this.inMSG.Get(activityContext)),
                        UiBrowser = new OutArgument<Browser>((ActivityContext)=> this.myBrowser.Get(ActivityContext))
                    },

                    new Assign<String>
                    {
                        To=new ArgumentReference<String>("outMSG"),
                        Value=new InArgument<String>((activityContext)=>this.inMSG.Get(activityContext))
                    }
                }
            };
        }
    }
}

This IS NOT possible in Invoke Code.

What’s d purpose of this please as we have Activities to use ?

https://github.com/Chevalier12/UiPath-Indicate-Element-Tool check this out, it’s a tool I made and it’ll let you understand what the difference is between creating activities in code rather than drag & drop in Studio.

Use Indicate Element in Studio and count the seconds it takes to get your selector then use my tool and you will see it’s almost instant.

Besides that, you can invoke as many workflows as you want simultaneously, without depending on any UiPath software, you’re basically using the Microsoft Workflow Foundation to invoke the activities in the UiPath library (is this against the ToS or something? Please let me know).

So to recap, code written activities are FASTER than Studio written activities (drag & drop), you have more control over what is in them, you can organize your code even better than in Studio and you can run as many workflows as you want at the same time.

Hey @Steve_Krozer

It’s amazing to see this !

But just thinking of dev friendly and less TAT in dev. I feel activities may be easy for everyone.

Thanks
#nK

1 Like