문제

I have a dataconfig.xml file that collects data from an Oracle database. In the Datasource element, I use variables such as ${dataimporter.request.dbname} that return successfully the custom value I passed via the dataimport url.

I am now writing a javascript transformer in this same dataconfig file to add values in a mutivalued field and that includes the database name. Is it possible to refer to the variable ${dataimporter.request.dbname} from within the javascript transformer? If so, what would be the correct syntax?

This is what I have tried, but dbname does not get populated:

function relatedItems(row) {
    var relatedItemsArray = new java.util.ArrayList();
    var dbname=${dataimporter.request.db_name};
    relatedItemsArray.add('type=DOCUMENT;datasource:PB||' + dbname);
    row.put('relation', relatedItemsArray);
    return row;
  }

Any help is greatly appreciated!

Thanks in advance.

도움이 되었습니까?

해결책

I just had that problem myself... The question is old, but just in case, this is how I passed a context variable to a script in the data import handler:

<entity name="fileline" processor="LineEntityProcessor" url="${filelist.fileAbsolutePath}" format="text" transformer="TemplateTransformer,script:relatedItems">
<field column="dbname" template="${dataimporter.request.db_name}"/>
</entity>

the TemplateTransformer will add the parameter in a new field, before passing the augmented row to the script. Then in the script:

    function relatedItems(row) {
        var dbname= row.get("dbname");
        var rawLine = row.get("rawLine");
        ....
    }

you can access your extra variable this way. It seems somewhat convoluted, but that's the best I could find (that works!).

다른 팁

You can access request parameters from the dataimport call from request context which is available to the script the same as 'row' is.

function myScript(row, context) {
  var dbName = context.getRequestParameters().get('db_name');
  ...
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top