1
votes

To create a view method to generate a computed column, you use some code like this:

private static server str createMySqlScript()
{
    str cellName = SysComputedColumn::returnField(tableStr(MyViewName), identifierStr(MyDataSourceName), fieldStr(TableName, ColumnName));
    return strFmt('LEFT(%1, 5)', cellName);
}

Works great for regular views, with regular data sources.

However, when you use a View with a query source, instead of traditional data sources, the entire thing falls apart.

On the first line: "Stack trace: The method has been called with an invalid number of parameters."

Anyone know how to call the name of a query field instead of a datasource field in a view?

2
Do you have an UNION view? - Matej
The query referenced by the view does use UNION. Does that change how you call the returnField() method? - Brad

2 Answers

0
votes

The code of returnField reads:

public static client server str returnField(TableName _viewName, str _dataSourceName, FieldName _fieldName)
{
    DictView dictView = new DictView(tableName2id(_viewName));
    return dictView.computedColumnString(_dataSourceName ,_fieldName, FieldNameGenerationMode::FieldList);
}

The second argument of the method must reference a valid datasource name:

The name of the data source on the view that contains the field which value is used as a return value.

Also for a union query it must be the first datasource in the query. By default query datasource names are appended and _1 suffix, the full name of the datasource including the suffix must be provided in the second argument. See the view for the correct name; the view fields will have that name in the Datasource property.

Beware that the intrinsic function identifierStr has no way to validate the input argument as opposed to other functions like tableStr.

0
votes

For views based on union queries, an integer parameter is passed to the computed column methods:

private static server str createMySqlScript(int iDatasource) {
str cellName = SysComputedColumn::returnField(tableStr(MyViewName), identifierStr(MyDataSourceName), fieldStr(TableName, ColumnName));
return strFmt('LEFT(%1, 5)', cellName);
}

If you do not define this parameter, strange things will happen... See https://msdn.microsoft.com/en-us/library/gg846293.aspx