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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

In mailserver thing, I need to update/change the configuration by using java script coding.

Hariharasuthan
13-Aquamarine

In mailserver thing, I need to update/change the configuration by using java script coding.

In mailserver thing, I need to update/change the configuration by using java script coding. How to do that?

 

ACCEPTED SOLUTION

Accepted Solutions

Hi @Hariharasuthan 

 

You can use the below service to get the Configuration Table definition and update it

 

The "GetConfigurationTable" service return the existing configuration table as InfoTable

 

You can update this InfoTable with new information and use the "SetConfigurationTable" service to update it

 

Velkumar_0-1689059056399.png

 

/VR

 

View solution in original post

5 REPLIES 5

Hi @Hariharasuthan 

 

You can use the below service to get the Configuration Table definition and update it

 

The "GetConfigurationTable" service return the existing configuration table as InfoTable

 

You can update this InfoTable with new information and use the "SetConfigurationTable" service to update it

 

Velkumar_0-1689059056399.png

 

/VR

 

@Velkumar - I want to add few more information about the query posted by Hariharasuthan.

We have a MailServer thing in which the SMTP configurations have to read and modified as per the user input (we have an equivalent MashUp SMTP screen).

Below is the code so far done

 

var mailServerThing = Things['SMTP-MailServer-Thing'].name;    // MailServer Thing Name

Things['SMTP-MailServer-Thing'].GetConfigurationTable({

// Here, what are all the properties we have to define to read and update the below SMTP parameters

//Parameter 1= Server
//Parameter 2 = Port
//Parameter 3 = Email
//Parameter 4 = Username
//Parameter 5 = Password
//Parameter 6 = SSL
});

 

If we can achieve this, we will be able to get the SMTP values from the Mashup and update them in the MailServer thing SMTP configuration table and send a test email to a test email ID (say aaa@aaa.co.in). If the test email triggered successfully then send a success message to that SMTP mashup screen.

 

@Velkumar - please guide, thank you.

Velkumar
19-Tanzanite
(To:SKannapiran)

Hi @SKannapiran 

 

Please find below code snippet 

 

// Get Configuration value from email server thing
let existingConfiguration = Things["EmailThing"].GetConfigurationTable({
	tableName: "ConnectionInfo" /* STRING */
});

// Update configuration based on User Input
existingConfiguration.smtpServer = Server; 			// SMTP Server
existingConfiguration.smtpPort = PortNumber;		// SMTP Server Port
existingConfiguration.accoundId = Email;			// Mail Account User
existingConfiguration.accountPassword = Password;	// Mail Account Password
existingConfiguration.useSSL = SSL;					// SSL 

// Update Configuration Table
Things["EmailThing"].SetConfigurationTable({
	configurationTable: existingConfiguration /* INFOTABLE */,
	persistent: true /* BOOLEAN {"defaultValue":true} */,
	tableName: "ConnectionInfo" /* STRING */
});

 

/ VR

Hi @Velkumar ,

 

After executing the above code in ThingWorx, I couldn't see the updated details in the MailThing's configuration.

I have doubt here, how the MailThing configuration parameters referred in the Javascript? Ex. In the MailThing configuration page, for SMTP Server, you have given as  "existingConfiguration.smtpServer". 

In this reply I have attached a screen shot which is captured after I executed your code snippet.

 

 

 

Velkumar
19-Tanzanite
(To:SKannapiran)

Hi @SKannapiran 

 

PFA working code. Once you run the 'setConfigurationTable' service, close and open mailThing again to see the updated configuration value.

 

To see configuration parameters, create a dataShape based on 'getConfigurationTable' service. In data shape, you can find the actual fieldName / parameters.

 

Or you can open browser devTools and check service response JSON for actual parameters.

 

Velkumar_0-1689238497672.png

 

/VR

 

Announcements


Top Tags