Ask Your Question
1

createRecord in JavaScript Evaluator returning null

asked 2019-05-01 16:35:07 -0500

tlochner95 gravatar image

I am trying to use a JavaScript evaluator to accomplish pretty much the same thing as this post accomplishes with a Groovy Evaluator. However, no matter what I try, I am getting null returned from the sdcFunctions.createRecord() method. Here is a snippet of the code I have written (note that the longestList variable here is irrelevant, but it is working properly:

for(var i = 0; i < records.length; i++) {
  for (var j = 0; j < longestList; j++) {

    // Create a new record.
    var newRecord = sdcFunctions.createRecord(records[i].sourceId + ':' + j);

    // Output the record.
    output.write(newRecord);
  }
}

However, the newRecord variable just writes null to the output. Here is a picture with the stream in preview:

image description

Also, note that the original records do have data in them initially, so that is not the issue.

I have also tried doing the same thing with a Jython Evaluator, although I am not familiar with Jython, but I got it to the same point I am at with the JavaScript Evaluator, and it did the same thing, returning null.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-05-01 17:07:25 -0500

iamontheinet gravatar image

updated 2019-05-01 17:49:49 -0500

Hi!

The new records ("New Output Record1", "New Output Record2", etc.) are being created but they appear "null" because you have not written code to add any field/column:value pairs.

Replace your code with the following snippet and see the change in output records.

for(var i = 0; i < records.length; i++) {
  for (var j = 0; j < longestList; j++) {

    // Create a new record
    var newRecord = sdcFunctions.createRecord(records[i].sourceId + ':' + j);

    // Add `field/column:value` pairs
    newRecord.value = {};
    newRecord.value['field1'] = 'val1';
    newRecord.value['field2'] = 'val2';      

    // Output the record
    output.write(newRecord);
  }
}

Cheers, Dash

edit flag offensive delete link more

Comments

Hello! Thank you so much for the reply! I tried this out, and it seemed to work! Thank you so much! I was already doing something similar, but I think I was doing it wrong. I had this: newRecord.value['field'] = value; Is there a way to just sort of "append" the field, as opposed to setting all?

tlochner95 gravatar imagetlochner95 ( 2019-05-01 17:14:53 -0500 )edit

You're welcome! Yes, you can append field/column:value pairs to the record dictionary as opposed to setting them all at once. See my updated code snippet.

iamontheinet gravatar imageiamontheinet ( 2019-05-01 17:51:59 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-05-01 16:35:07 -0500

Seen: 130 times

Last updated: May 01