Complex report with links using Razor markup

Useful information
This article is the last in the series about creating links in reports.
The first article describes creating links in general. You can find it here.
The second article describes creating links to different object types in one report. You can find it here.

 

Consider the previous report example but with Razor markup.

Open the Display Settings tab and select Report Layout - .NET Razor.

The Report Layout tab will change to Report Layout (.NET Razor), which contains an empty pane for Razor markup.

To learn more about Razor, read this article. 

Create a report layout using the Template Wizard. 

 

You can read how to work in the template wizard here.

As the result, you get a code generated by a template.

First, let's take a look at a simple link to the ELMA profile of a task author.

To add a hyperlink to the author field (to make the SQL query simpler, use only the ID, without the full name and job position), find the code section, that forms this field:

<span><span><td></span></span><span><span>
    @* Get the value of the AuthorId column from the current line *@</span></span><span><span>
    @ Row ["AuthorId"]</span></span><span><span>
</ TD></span></span>
 

Delete the @row["AuthorId"] line and click Create Link.

Link creation wizard will open, where you need to fill out the fields according to the report:

Link Type – Entity, an ELMA object, which is not a report.

Object Type – user.

ID Field – AuthorId, this is the field you get with the SQL query.

Link Name Field – AuthorId, this is the field that will be displayed as the link name. In this case, it the task author ID.

Open in New Window – check this box if you want the link to open in a new browser tab/window.

After clicking OK, you get the following code fragment:

<span><span>            <td></span></span><span><span>
                @* Get the value of the AuthorID column from the current line *@</span></span><span><span>
               @ Url.EntityLink (row, TypeOf (EleWise.ELMA.Security.Models.IUser), "AuthorID", "AuthorID", true)           </span></span><span><span>
            </ TD></span></span>
 

Start debugging and see the resulting report. The constant part of the link is selected automatically, i.e clicking on the name with the task author ID opens their profile in the new tab.

Now let's create links to different types of tasks.

For this, use a standard Razor structure (in this case the structure is the same as an HTML structure)

<span><span><a href="link">displayed name</a></span></span>
 

Find the code section that generates the field with the task name

<span><span><td></span></span><span><span>
                @* Get the value of the Name column from the current line *@</span></span><span><span>
                @ String ["Name"]</span></span><span><span>
</ TD></span></span>
 

Insert the Razor code that generates a link:

<span><span><td></span></span><span><span>
                @* Get the value of the Name column from the current line *@</span></span><span><span>
               @ If (@ row ["Uid"]. ToString () == "20404079-49d9-4068-9de5-4ecd2c750868") { </span></span><span><span>
        <a href="/Projects/ProjectTask/Execute/@row["Id"].ToString()"> @ successively ["Name"] </></span></span><span><span>
        } And {</span></span><span><span>
        <a href="/Workflow/WorkflowTask/Execute/@row["Id"].ToString()"> @ successively ["Name"] </></span></span><span><span>
        }</span></span><span><span>
</ TD></span></span>
 

As the result, you get a report on project and process tasks with links.