Method CRM Try it FREE
 Method CRM Help Center
 Search  
Overview
Getting Started Checklist
Customization
Method FAQ


collapse all | expand all
Scripting
Solution No. 416

OVERVIEW
Script examples

Overview

Some of you who are familiar with programming or coding may already know what scripting is all about.  A script is a program that automates the execution of tasks within a larger process.  Those familiar with Visual Basic will have a solid understanding of these principles, but the average user probably will not.

It sounds complicated, and frankly it is.  This documentation will not teach you how to script, because there are literally university courses taught on the subject, but it will direct you to where you can find the scripting tool in Method Report Designer and supply some examples of scripts that perform basic functions within the Report Designer environment.

Scripting options are available in the Behavior section of whatever section of the report or control you happen to be working in.  Whether you have selected the property grid itself, a specific band, or even a specific control, you will be able to find the scripting tool under Behavior > Scripts.  Please note that any scripts you use will only influence the information in the section you have selected (e.g. if you have selected a single control like a label and then implement scripting, the script will only affect information within that label).

Clicking the + icon next to Scripts will open a larger menu of events you can attach a script to - this means you are choosing what must happen before the script is activated.  

Clicking the ellipses button [...] next to an event option will open the scripting editor, which looks like this:



The first thing you’ll notice is two pieces of text: Private Sub and End Sub.  It’s helpful to think of these two pieces of text as bookends for your code: if you’re familiar with basic HTML, another good analogy would be to think of them as the < p > and < /p > tags that block off a paragraph.  Regardless, it’s important you don’t delete them!  The code in between these two tags is the default code provided by Report Designer.  You can delete it and include your own code as you desire.

The body of the script you’ll be using is heavily dependent on what you want the script to do.  As we stated at the beginning of this section, our intent here is not to teach coding, so instead we’ve included a few examples below of pre-made pieces of code that can be copy-pasted into the scripting editor to achieve different effects.  Remember, these pieces of code must go between the Private Sub and End Sub markers in order to take effect.

back to top

Script examples

Calculated script for getting parent

This script works to retrieve the main parent customer from a group of customers and jobs.

Iif(CharIndex(':', [Customer]) = -1,[Customer] ,Substring([Customer],0,CharIndex(':', [Customer] ) ))

Basic grouping

This script works to group the data in your report by a specific field; in this case, by sales rep.

Dim xrc As XRChart = CType(sender,XRChart)

Dim filtervalue As String = GetCurrentColumnValue("SalesRep").ToString

xrc.Series(0).DataFilters.Clear

xrc.Series(0).DataFilters.Add(New DataFilter("SalesRep", "System.String", DataFilterCondition.Equal, filtervalue))

Manipulating diagram size

This script works to change the range of the diagram you are referencing - this works for charts!  In this example, twelve values will show up if the argument is "day", and if not, 60 will show up.

Dim xrc As XRChart = CType(sender,XRChart)

Dim diagram As XYDiagram = CType(xrc.Diagram, XYDiagram)

If ReportType.text = "Day"
diagram.AxisY.GridSpacing = 1
   diagram.AxisY.Range.MaxValue = 12
Else
   diagram.AxisY.GridSpacing = 5
   diagram.AxisY.Range.MaxValue = 60
End If

back to top

 

Was this article helpful?