Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in RPA by (5.3k points)

I am a Blue Prism RPA Developer and I want to create methods in my global code and call them from other code stages. In Global code info page, it is stated that this could be done but i could not find a satisfactory resource on the subject. Can anyone share a syntax rule set, maybe a sample global code and code stage code sniplets or guide me in the direction? I use C# and i would much appreciate responses in C#

Note: I am not from a developer background, i have elementary coding know how but i am not entirely knowladgeable about OOP subjects (namely: Classes, Methods, Constructors, Inheritence etc)

I tried declaring one class and one method, that worked, i could call the method but when i tried to add new method and or class it failed, it did not compile with the overall code

1 Answer

0 votes
by (9.5k points)

Since you are using C#, your first stop should be the Code Options tab. 

Here you should reference any libraries you intend to use (.dll) on the top pane, and their respective namespaces in the bottom pane. 

 It is also very important to change the Language selection to C# (bottom left drop-down), as Visual Basic seems to be the default option:

enter image description hereNext, here is an example of a simple concrete class with some fields, a constructor, a property and a method. You can place this code inside the Global Code window as-is:

public class SomePerson { //Class variables private string _firstName; private string _lastName; //Constructor public SomePerson(string firstName, string lastName) { this._firstName = firstName; this._lastName = lastName; } //Property public string FullName { get { return string.Format("{0} {1}", this._firstName, this._lastName); } } //Method public string Hello() { string myText = "Hello "+FullName+", it is nice to meet you."; return myText; } }

Now you will be able to call instances of this class from inside code-stages and use the property and the method. For example, you could supply the FirstName and LastName in a couple of data items in BP, and then use an instance of the SomePerson class property to get the FullName using this code:

SomePerson Anyone = new SomePerson(firstName, lastName); fullName = Anyone.FullName;

Similarly, you could use the method as follows:

SomePerson Anyone = new SomePerson(firstName, lastName); result = Anyone.Hello(

You could try all this out using a layout like this one:

enter image description here

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...