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

ThingWorx Navigate is now Windchill Navigate Learn More

Translate the entire conversation x

email link to file in a repository

steve237
14-Alexandrite

email link to file in a repository

I'm using ThingWorx 9.3.9

 

My service creates a file in a file repository.  I would then like the service to email a link to the file that the user can click on to download the file.

 

I've tried using the repository's GetFileListingWithLinks service that returns an infotable that has a hyperlink field named downloadLink.  However, the value that is returned is in this format:

/Thingworx/FileRepositories/MLLC.Common.Repository/LineZRouteID_2025-08-07.csv

 

When I email that value Outlook does not recognize that value as a link.  So, I think I need to somehow convert it to this format:

http://thingworxu15/Thingworx/FileRepositories/MLLC.Common.Repository/LineZRouteID_2025-08-07.csv  

 

Here's my code.  The commented lines show the ways I tried to get it to email a proper link.

// result: INFOTABLE dataShape: "FileSystemFileWithLinks"
		let fileInfo = Things["MLLC.Common.Repository"].GetFileListingWithLinks({
			path: "/" /* STRING */ ,
			nameMask: validationID + "_" + formattedDate + ".csv" /* STRING */
		});
		//linkToCSV = "<a href=" + fileInfo.downloadLink + "></a>";
        //linkToCSV = "<a href=" + fileInfo.downloadLink.toString() + "></a>";
        //linkToCSV = fileInfo.downloadLink.removeAttribute('href');
        linkToCSV = fileInfo.downloadLink;
         
        let body = "<html><body>" + linkToCSV + "</body></html>";

		// send message
		Things[me.emailThingName].SendMessage({
			cc: undefined /* STRING */ ,
			bcc: undefined /* STRING */ ,
			subject: validationID + " Updates Needed" /* STRING */ ,
			from: undefined /* STRING */ ,
			to: emailList /* STRING */ ,
			body: body /* HTML */
		});

 

However, this is what I get - no link.

steve237_1-1754664375757.png

 

I know that I can build the link, but that would require the code to be updated with the new host as we move from Dev to Test to Production.  Something, I'd like to avoid.

 

Thanks,

Steve

 

 

 

 

ACCEPTED SOLUTION

Accepted Solutions

The server does not know the URL itself. You have to set it somewhere manually and adapt it for each instance.

 

Our best practice is to create an "Environment"-Thing with a ConfigurationTable which holds different useful values like hostname, envName, sendEmails,.. These can be then used by different UseCases to get the information.

 

In your service you would then do a

let link = "https://"+ Things["EnvironmentThing"].GetConfigTable().hostName + fileInfo.downloadLink; // (pseudocode)

but you can also use a property or something else to store the information. (But properties may change value on extension update, so configtable is our prefference).

View solution in original post

6 REPLIES 6

The server does not know the URL itself. You have to set it somewhere manually and adapt it for each instance.

 

Our best practice is to create an "Environment"-Thing with a ConfigurationTable which holds different useful values like hostname, envName, sendEmails,.. These can be then used by different UseCases to get the information.

 

In your service you would then do a

let link = "https://"+ Things["EnvironmentThing"].GetConfigTable().hostName + fileInfo.downloadLink; // (pseudocode)

but you can also use a property or something else to store the information. (But properties may change value on extension update, so configtable is our prefference).

PEHOWE
17-Peridot
(To:steve237)

Hello @steve237 
Have you considered using:

 "IPAddress = Resources["CurrentSessionInfo"].GetCurrentIPAddress();"

This does not get the entire URL but it does get part. There are 2 items which I think you might be missing.
The protocal: "http" or "https"
The port number would be the other item which you seem to be missing.
I am checking to see if that is available?

Regards,
pehowe

Https won’t work with an IP address.

Vilia (my company) | GitHub | LinkedIn
PEHOWE
17-Peridot
(To:PEHOWE)

Hello @steve237 ,
I did a little example and using http worked.
Please review the information presented and let me know if you have any questions.

 

Regards,

Pehowe

 

Do you suggest them using plain unencrypted http in production? This won’t work with httpS because their TLS certificates will be issued for domain names, not for IP addresses.


Vilia (my company) | GitHub | LinkedIn
steve237
14-Alexandrite
(To:PEHOWE)

@PEHOWE,

Thanks, but when I tried using your suggestion (IPAddress = Resources["CurrentSessionInfo"].GetCurrentIPAddress();)  it returned the IP address of my laptop, not the server,

Announcements


Top Tags