Create Custom Rule In Workflow Analyzer

Hi ,

How to write custom rule using visual studio.
Please Help ?

Regards,
Zaid.

@MohdZaid,

This link will get you started, but it leaves many unanswered questions:

I’ve taken to decompiling the existing rules and seeing how they were created. :frowning:

I will update this tread as I figure things out.

The first bit of information I have to share is about the scope of your rule. The documentation describes three scopes, activity, workflow, and project. However, the documentation doesn’t describe how you can set the scope of your rule. Moreover the code examples only show rules that will return the Activity scope. Here is how you can determine what scope your rule affects:

Here is the VariableLengthRule that is given as an example in the documentation:

Here is the code Get Method:

 internal static Rule<IActivityModel> Get()

Note the method returns an object that implements the IActivityModel interface. This rule is scoped to the activity.

The rule for HardCodedDelays checks workflows for violations.

internal static Rule<IWorkflowModel> Get()

Note it’s return type is an object of the IWorkFlowModel interface. The scope of this rule will be the workflow.

Lastly, we have CheckProjectJSONFile exists. This rule applies to the project level.

internal static Rule<IProjectModel> Get()

The return object is of the IProjectModel interface.

image

1 Like

The next tip I have to share is how you can easily debug your custom rules.

  1. Once you’ve compiled your rules into a library, *.dll, copy the dll into the path of Uipath Studio as indicated in the documentation. Usually this is program files (x86)/UiPath/Studio/Rules.
  2. Open UiPath Studio to a project you wish to analyze.
  3. Use the debug option in Visual Studio to attach to a process.

image

You should see a process called UiPath.Studio.Analyzer.exe. Select it and click the “Attach” button.

image

At this point you can set a break point in Visual Studio.

The rule I am debugging is at the project scope, so use the Analyze Project option in UiPath.

image

The debugger should halt on the break point, allowing your to examine the values of all local variables.

image

3 Likes

Hi @cclements

We love your feedback :slight_smile:

If you feel like it, please do contribute towards our documentation as per this topic:

Our docs team will go over your suggestion :slight_smile:

Thanks @loginerror!

If I can think of a good approach I may make recommendations. I have contributed documentation in the past. A good start may be documenting the methods and properties of the activity, workflow, and project objects. Understanding what can be interrogated and where, is key to creating rules.

Chris

1 Like

Hi @loginerror

Documentation provided by UiPath is little abstract on building the custom rules. I tried to build the rules with the uipath but facing issues related to syntax in visual studio.

It would be great, if UiPath has detailed about the steps for creating the custom rules at least for one rule.

Existing documentation is leaving many unanswered questions.

@cclements, @MohdZaid
I already referenced UiPath.Activities.API in the project. I am not sure what are all the namespaces which need to be included here in order to get rid of the following syntax errors.

image

2 Likes

You have asked in a good moment. There has just been a cool webinar with a step by step guide on how to achieve that :slight_smile:the recording should be available soon here:
https://www.techgig.com/webinar/Learn-about-the-latest-features-from-Uipath-Activity-Creator-and-Workflow-Analyzer-1734
(to access the recording you have to create an account)

Now also simple available on YT :slight_smile:

3 Likes

Wow. I must say it is very detailed.
@loginerror you saved a lot of time for me. Thanks a ton.

1 Like

Hi, I saw the Webinar and it’s very useful, but here it doesn’t specify how can we access other data in a uipath file like for example how to check annotatios, how to check if’s, etc, is there a way to do it? Thank you very much :slight_smile:

1 Like

Hi @TomaB @DeanMauro @mircea @loginerror
I saw your presentation and replicated the exact same rule in visual studio, built the dll, and copied it to the uipath rules directory. But this rule is not getting reflected in the workflow analyzer rules.
What could be the reason? did I miss something??
UiPath Studio version:2019.10.1
Library created with .net framework 4.6.1

@loginerror
Strangely the custom rule I created is not working in 2019.10.1 image

It is working fine in image

Hi @Hawkins!

The first thing to consider is if you used IRegisterMetadata method? This method is only available from Studio 2019.10.6 and forward and might explain the behavior you’re mentioning.

1 Like

Hi @nerlichman @loginerror,

I made good progress with respect to building the custom rules. However I am stuck at making one rule. The rule should check for a pattern in the display name of the activity.
something like this: DefautName_browser_application
So I will first check if it is starting with the default name, split the string using “_” and see if the length is 3.

image

I can fetch the display name with the following attribute.

image fetches “Attach Browser_google_converter” in the above case.

Let’s say if the developer named it image
Ideally it should be AttachBrowser_Google_Converter
Now my rule should trigger an error. But I have no clue on how to get this default name “attach browser” of the activity.

The above mentioned is just one example, I will be requiring this default name for all most all the activities for some or the other reason.

Could you please help me with this?

Tagging few others for better reach.
@lakshman @bcorrea

1 Like

Hi @Hawkins!

Sorry for the delayed response!

I haven’t tried that yet, but I’ll try to check it out and let you know what I found. It may take me a few days though.

Meanwhile maybe @DeanMauro has more insights about your question.

Hi @nerlichman, I have not used IRegisterMetaData Method, I implemented IRegisterAnalyzerConfiguration interface as per the video.

I just did exactly how its shown in the video and tried to install it as Dependency with NuGet Package, the rule does not show up , please direct me on what i need to check ?

Hi @loginerror,

I am not able to get the versions of each dependency.Could you please guide me on how to get that value.

Thanks in advance
Sharmila

Hi @nerlichman,

After adding the dll into UiPath Rules Folder ,I am not able to see the rule in Workflow Analyzer.Can you please guide me where i went wrong.

Thanks in advance
Sharmila

Hi @mukund.jahagirdar!

First of all, sorry for the delayed response. I haven’t had time to check the forum much this past month.

Were you able to make it work? If now, could you let me know which Studio version are you using?

You created the rule in the example or created your own by following the video?

Did you tried to add the rule at a global level? If that works, the problem could be in the nuget package generation

Hi @SharmilaSundar!

Could you let me know your Studio version and which registration method did you use?