cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get value of the field defined in Configuration Table while building an extension.

SOLVED
Newbie

How to get value of the field defined in Configuration Table while building an extension.

I can see option only for getDefaultValue() not getValue(). I followed as:

     getConfigurationTable("TableName").getField("fieldName").getDefaultValue().

The option for getValue() was not there, hence changes in configuration is not reflectiong after importing this extension in Thingworx Platform.

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to get value of the field defined in Configuration Table while building an extension.

Hi Vladi,

The below command worked for me -

     getStringConfigurationSetting("TableName", "PropertyName");

Regards,

Nitin

15 REPLIES 15

Re: How to get value of the field defined in Configuration Table while building an extension.

Hi Nitin,

Could you try getConfigurationData().getValue("TableName", "PropName") ?

Best regards,

Vladi

Re: How to get value of the field defined in Configuration Table while building an extension.

Hi Vladi,

The below command worked for me -

     getStringConfigurationSetting("TableName", "PropertyName");

Regards,

Nitin

Re: How to get value of the field defined in Configuration Table while building an extension.

Hello,

If this is the correct answer, then could you please mark it as correct to help other developers find the answer to this in the future?

Thanks!

Tori

Re: How to get value of the field defined in Configuration Table while building an extension.

Can you please provide code example?

String myProp = getStringConfigurationSetting("TableName", "PropertyName");

Is it just like this?

Re: How to get value of the field defined in Configuration Table while building an extension.

Actually found answer in apendix A of thingworx_extension_development_user_guide.pdf.

@ThingworxConfigurationTableDefinitions(tables = {

@ThingworxConfigurationTableDefinition(name="ConfigTableExample1", description="Example 1 config table", isMultiRow=false, dataShape = @ThingworxDataShapeDefinition( fields = { @ThingworxFieldDefinition(name="field1",description="",baseType="STRING"), @ThingworxFieldDefinition(name="field2",description="",baseType="NUMBER"), @ThingworxFieldDefinition(name="field3",description="",baseType="BOOLEAN"), @ThingworxFieldDefinition(name="field4",description="",baseType="USERNAME")})),

@ThingworxConfigurationTableDefinition(name="ConfigTableExample2", description="Example 2 config table", isMultiRow=true, dataShape = @ThingworxDataShapeDefinition( fields = { @ThingworxFieldDefinition(name="columnA",description="",baseType="STRING"), @ThingworxFieldDefinition(name="columnB",description="",baseType="NUMBER"), @ThingworxFieldDefinition(name="columnC",description="",baseType="BOOLEAN"), @ThingworxFieldDefinition(name="columnD",description="",baseType="USERNAME") })) })

String field1Value = (String)getConfigurationSetting("ConfigTableExample1", "field1");

Double field2Value = (Double)getConfigurationSetting("ConfigTableExample1", "field2");

Boolean field3Value = (Boolean)getConfigurationSetting("ConfigTableExample1", "field3");

String field4Value = (String)getConfigurationSetting("ConfigTableExample1", "field4");

Re: How to get value of the field defined in Configuration Table while building an extension.

It there any way to handle configuration change? For example regenerate internal values base on that config?

Maybe some event?

Re: How to get value of the field defined in Configuration Table while building an extension.

Hi Jan,

There's no such an event regarding the configuration. Considering the typical usage, you always read the configuration parameters when you start the Thing.

If you need such a functionality you can store in internal properties (maybe an infotable holding all previous parameters) the old values then compare the new values to the old ones?

Re: How to get value of the field defined in Configuration Table while building an extension.

I wanted to put internal logic to custom class:

MyCustomLogic cl = new MyCustomLocic(config1, config2);

Then in services:

     cl.method1();

I dont want to do:

     cl.setConfig(config1, config2);

on every service call...

Any solution to this?

Re: How to get value of the field defined in Configuration Table while building an extension.

You can use that. It's only that because there's no event for "data change" for the configuration - since it's not a property - you need to actually store each time the previous "config" to a store of your own. For this you can use the Infotable, or anything that you'd like.

Then, each time when you start the thing, the config1 will be the current config, and config2 will be something like "readPreviousConfigFromStore".

Makes sense?