Set strings collection property from custom action

I’m implementing a custom action using C#.Net 2.0. I need to return a collection of strings from the OnExecute() method. However, the Context (IFBCustomActionExecuteContext) doesn’t appear to expose a method or property to achieve this. I was expecting:

Context.Properties.set_PropertyAsStrings(“MyProperty”, someArray);

but there is no “set” for the collection (just bool, double, int, string, variant). How can I accomplish returning a collection (like List Iterator does)?

Thanks!

Hi Jeff,

The PropertyAsStrings properties are actually IFBStrings objects, which have their own interface for access. Rather than replacing the entire object, you can work with it. Unfortunately, the interface is missing a couple of useful methods - namely Clear and an AddCollection() method. You’ll need to work around it like this:

IFBStrings mystrings = Context.Properties.get_PropertyAsStrings(“SomeProperty”);
while(mystrings.Count > 0)
{
mystrings.Delete(0);
}
foreach(string s in myCollection)
{
mystrings.Add(s);
}

I’ll add a Clear() and a SetCollection() method to the to-do list for the next major release.

Regards,

Angus

Does anything appear incorrect in this code block? I know the IFBStrings object is populated properly because I’m logging it. However, the variable I’m setting through the action’s “Systems” Strings (note the plural) property remains empty.


string[] systems = new string[2] { “system1”, “system2” }; // just as an example
IFBStrings fbSystems = Context.Properties.get_PropertyAsStrings(“Systems”);

foreach (string s in systems)
{
fbSystems.Add(s);
}

Context.SetVariable(Context.Properties.get_PropertyAsString(“Systems”), fbSystems);


Thanks.

Hi Jeff,

What are you trying to achieve with the Context.SetVariable() call? SetVariable sets a FinalBuilder variable inside the FinalBuilder runtime, not inside the Action itself. Do you just want to write the values in fbSystems “back” to the action property? If so, there is no need - fbSystems will be a reference to the property on the action (they’re both the same object.) Attempting to retreive an object of type IFBStrings as a String, and then use it as a variable name, is very unwise.

Regards,


Angus

Well I don’t want to pursue the unwise! Here’s what I need to accomplish: I have an array within my .Net 2.0 custom action. I need to return the values within this array as a FB property back to the FB project. I have a Strings FB Property named “Systems”. How can I accomplish this?

Further, is this the proper method of populating variables tied to properties of a custom action?

Thanks.

Hi Jeff,

Glad to know you’re keeping away from the unwise. ;-).

Here’s how I would do this:

1) Add a property to your custom action in ActionStudio. Make the property of type “String” and call it something like “SystemsVariable”.

2) Place a “Variable ComboBox” control on the property page for the aciton and bind it to “SystemsVariable”.

3) Add a label to the combobox, something like “Save Systems to Variable"

4) In the assembly, put some code like this

string[] systems = new stringΐ] { “system1”, “system2” }; // just as an example

string sysVariable = Context.Properties.get_PropertyAsString(“SystemsVariable”);
string systemString = String.Join(”\r\n", systems);

Context.SetVariable(sysVariable, systemString);


… at runtime, the above code will populate the chosen variable specified in the “SystemsVariable” property with the contents of the systems array, as a CRLF-delimited string. CRLF-delimited strings are more useful in almost all cases where FinalBuilder actions use “list” type items (List Iterator, Prompt For Variables combo boxes, etc.)

Please let me know if I’ve missed the point somehow.

Regards,

Angus

Perfect. That did it. I wasn’t grabbing the variable as well as trying to return a property of Strings instead of just String.

Thanks.