1. Home
  2. /
  3. Docs
  4. /
  5. Articles Report Writer
  6. /
  7. Report Functions
  8. /
  9. DataSoft Functions

DataSoft Functions

DataSoft functions are Articles-specific utility functions that provide additional capabilities beyond the standard function library. They are available throughout the Articles report script editor.


Clamp

Restricts a value to within a specified minimum and maximum range. If the value is below the minimum the minimum is returned, if above the maximum the maximum is returned, otherwise the value itself is returned. See also IsBetween for checking a range without clamping.

Clamp(Value, Min, Max: Double): Double
ParameterTypeDescription
ValueDoubleThe value to clamp
MinDoubleThe minimum allowed value
MaxDoubleThe maximum allowed value
// Ensure a discount rate never goes below 0 or above 50%
Result := FormatNumberSafe(Clamp([Orders.DiscountRate], 0, 0.5), 2);

// Cap a commission rate between 1% and 15%
var rate := Clamp([Employee.CommissionRate], 0.01, 0.15);
Result := FormatFloat('0.00"%"', rate * 100);

// Keep a quantity within valid bounds before processing
var qty := Clamp([Orders.Quantity], 1, 9999);
Result := IntToStr(Round(qty));

QuotedStr

Returns a string value enclosed in single quotation marks. Useful when building dynamic SQL strings or constructing text that requires quoted values.

QuotedStr(V: Variant): String
ParameterTypeDescription
VVariantThe value to wrap in single quotes
Result := QuotedStr('Acme Corp');
// Returns: '''Acme Corp'''

// Build a SQL-style WHERE clause string
var filter := 'AccountNo = ' + QuotedStr([Customer.AccountNo]);

// Useful when constructing parameterised strings dynamically
Result := 'WHERE CustomerID = ' + QuotedStr(VarToStr([Customer.ID]));

RoundToN

Rounds a number to a specified number of decimal places. See also RoundTo2 for the common case of rounding to 2 decimal places.

RoundToN(V: Double; N: Integer): Double
ParameterTypeDescription
VDoubleThe number to round
NIntegerNumber of decimal places to round to
// Round a weight to 3 decimal places
Result := FormatNumberSafe(RoundToN([Item.Weight], 3), 3);
// Returns: '12.456'

// Round an interest rate to 4 decimal places
Result := FormatNumberSafe(RoundToN([Finance.InterestRate], 4), 4);
// Returns: '0.0675'

// Round to a whole number
Result := IntToStr(Round(RoundToN([Stats.Average], 0)));

SetParam

Sets a parameter value on a named dataset at runtime. Use this to pass values into a stored procedure or parameterised query from within a report script, typically in a BeforeStartReport or BeforePrint event.

SetParam(DataSetName, ParamName: String; Value: Variant): Variant
ParameterTypeDescription
DataSetNameStringThe name of the dataset component in the report
ParamNameStringThe name of the parameter to set
ValueVariantThe value to assign to the parameter
// Set a date range on a stored procedure dataset
SetParam('spSalesData', 'StartDate', [Param.StartDate]);
SetParam('spSalesData', 'EndDate',   [Param.EndDate]);

// Pass a customer ID to filter results
SetParam('spCustomerOrders', 'CustomerID', [Customer.ID]);

// Use Sage period dates as parameters
SetParam('spPayroll', 'PeriodStart',
         SagePeriodStartDate([ConnectionDef], [Param.Period]));
SetParam('spPayroll', 'PeriodEnd',
         SagePeriodEndDate([ConnectionDef], [Param.Period]));