When and how to use Invoke Method activity || UiPath

Pradumn Kumar
4 min readNov 15, 2022

--

Are you confused when to use Invoke Method activity and how to use it!?

We often use “methods” in UiPath to achieve required results. Generally, we do it through Assign activity. But there are some methods for which have to use Invoke Method activity! Why should we do that? Why can't we keep using our beloved Assign activity?

Worry no longer! Just read this short blog and it will be crystal clear to you about where and how to use an Invoke Method activity instead of Assign activity. The trick is to check if a method returns any value!

When and How of Invoke Method activity in UiPath

The Assign activity scenario

The UiPath intellisense will be our savior in understanding this topic. Let's look at below samples:

All the above methods have 3 components in common:

-> Method Name [Equals, Contains, Copy, StrReverse]

-> Input Arguments [Equals method takes 2 arguments while others here take 1. Some methods don’t require any input arguments.]

-> Return Value [Boolean, String: Focus on the last part of the snapshot starting with ‘As ….’]

So, do we need Invoke method activity here? NO. Since all above methods are returning values, we can assign the returned value to a variable on left side of Assign activity! Below is the example usage of the StrReverse method where we store the reversed string (return value) to a variable TestString1:

Sample usage of StrReverse() which returns a string

The Invoke method scenario

Now let’s have a look at some other methods:

Did you notice any difference? Yes, you guessed it right! None of these have any return type. So, we will have to use Invoke Method activity! This activity requires either the TargetType or the TargetObject. Also, you can pass arguments to the method through the Parameters property, if required.

Example-1 : Using Clear() through Invoke Method activity

  • TargetObject : A list [I have used a variable SampleList]
  • MethodName : Clear
  • Parameters : [None required in this case]
Fig: UiPath Studio code for List.Clear()

Example-2 : Using SetOrdinal() through Invoke Method activity

  • TargetObject : A DataColumn [I am referring to TestColumn3 from a DataTable named SampleDataTable]
  • MethodName : SetOrdinal
  • Parameters : 1 integer input argument [I am passing 0 to shift that column to 1st position!]

Voila! Now you know when and how to use Invoke Method activity!!

Revision: When in doubt about the need for Invoke method, just make use of UiPath intellisense and check if the method returns any value or not!

Feel free to Follow me for more such easy-to-understand content. I am also available on LinkedIn :-)

Thank you for your time!! See you soon.

--

--

Pradumn Kumar
Pradumn Kumar

Written by Pradumn Kumar

Hey there! I’m a software professional with 5+ yrs of overall experience. I’ve deep interest in tech and geopolitics, which lures me deep into these topics.

No responses yet