Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Dev Space

Customize and extend the power of Alteryx with SDKs, APIs, custom tools, and more.
SOLVED

C# DotNet Tools: How to copy a record?

Hiblet
10 - Fireball

TL;DR: DotNet Tools Examples use SetFromString(), but Blob types do not work with this approach - Is there a way to copy or clone a record that I am missing?


I've written about 5 or 6 C# DotNet plug in tools, and they work nicely with limitations. The tools all take records in, do something, and add some fields to the records.

 

Currently, to pass the records through the tool, I do the following, once, in II_Init()...

- Create a new RecordInfo object called recordInfoOut.
- Iterate over recordInfoIn, get each FieldBase, and call recordInfoOut.AddField() using each inbound FieldBase.
- Call recordInfoOut.AddField() to add any extra fields I am going to add to each record.

This creates the format for the output record.

 

As the tool processes each individual record, I copy the data from the inbound record to the outbound record, extracting the string from the FieldBase using GetAsString() and using SetFromString() to set the new FieldBase, in II_PushRecord(). The examples in the C# SDK documentation use this method.

 

That works fine for simple field types that translate easily to string.

 

The problem is that when there are FieldTypes like Blob, there is no string representation, and I get an SEH unhandled exception when I try to use String type to copy.

 

Currently I work around this by not including Blobs in the inbound data stream. However, I am thinking that I might be doing something wrong in using string as an intermediary data type, and really there should be some record level Copy or Clone method around that allows me to copy inbound FieldBases to outbound FieldBases without changing type.

 

I have found the RecordCopier class and the member Copy, but I have no example code of how it should be used, and when I try to use it, Alteryx crashes out on me. I must be using it incorrectly.

 

Does anyone have any example implementations of NetPlugIn classes that can pass all FieldTypes through? I'm not asking to be spoonfed, but if you can give me any direction, I would really appreciate it.

3 REPLIES 3
jdunkerley79
ACE Emeritus
ACE Emeritus

Hi @Hiblet,

 

I use the record copier all the time in C# and it works fine. I have wrapped a lot of the boiler plate code up in my Omnibus nuget package but have plugged it back into one block of code:

 

// Init Copier (II_Init)
var copier = new RecordCopier(recordInfoOut, recordInfoIn, true); for (var fieldNum = 0; fieldNum < info.NumFields(); fieldNum++) { var fieldName = info[fieldNum].GetFieldName(); var newFieldNum = recordInfoOut.GetFieldNum(fieldName, false); if (newFieldNum == -1) { continue; } copier.Add(newFieldNum, fieldNum); } copier.DoneAdding(); // Copy a Record pushed (II_PushRecord) this.Output.Record.Reset(); copier.Copy(this.Output.Record, pRecord);

Tested quickly on my datetime parse tool and blobs are copied fine.

 

Happy to skype etc if it dont work!

 

 

 

 

 

Hiblet
10 - Fireball

ACE to the rescue!  That is great, it works.

 

A thousand thanks to @jdunkerley79, for that.  I can now pass a blob through the tool.

 

I am interested though, this is not in the example documentation, how did you find this out?

 

 

jdunkerley79
ACE Emeritus
ACE Emeritus

Back and forth between c# and c++ and too much time digging.

All my code is on github if you want to nose: https://github.com/jdunkerley/AlteryxAddIns