Page 1 of 1

HTML-table as variable in HTML-mail?

Posted: Mon Nov 28, 2022 9:51 pm
by magnussandstrom
Hi!

I have a (variable) html table (as a html file) that I want to embed as a part of a html email in Switch. The email html has other Switch variables in it, but I can't figure out how to embed my table. Any suggestions?

ps. I also have the table as a CSV if that can be used some how.

Re: HTML-table as variable in HTML-mail?

Posted: Tue Nov 29, 2022 9:11 am
by freddyp
Put the HTML of the table in private data and place that variable in your HTML template.

Re: HTML-table as variable in HTML-mail?

Posted: Tue Nov 29, 2022 9:24 am
by magnussandstrom
freddyp wrote: Tue Nov 29, 2022 9:11 am Put the HTML of the table in private data and place that variable in your HTML template.
Any suggestion how? The HTML-table is a file, not metadata.

Re: HTML-table as variable in HTML-mail?

Posted: Tue Nov 29, 2022 1:42 pm
by JimmyHartington
Could you read it in as Privatedata.

Re: HTML-table as variable in HTML-mail?

Posted: Tue Nov 29, 2022 2:13 pm
by freddyp
I have not tested it, but I think the "Create file from template" app can insert a file into a file.

Re: HTML-table as variable in HTML-mail?

Posted: Tue Nov 29, 2022 4:07 pm
by JimmyHartington
I have this legacy script-code I have used earlier.

Code: Select all

/*
  This script reads the body of a file to private data.
*/

function jobArrived( s : Switch, job : Job )
{
	// Set some property stuff
	if(s.getPropertyValue('Debug') == 'Yes'){
		var debug = true;
	} else {
		var debug = false;
	}
	
		
	if(job.isFile())
	{
		// Make temp file
		var htmlData = File.read(job.getPath(), "UTF-8");

		
		// Set to PD
		job.setPrivateData("text", htmlData);

		
		// Debug
		s.log(1, 'TXT: ' + htmlData);
		
		// Send along
		job.sendToSingle(job.getPath());
		
	} else {
		// Not supporting folders
		if(debug) s.log(2, 'Input job was folder.');
	}
}

Re: HTML-table as variable in HTML-mail?

Posted: Wed Nov 30, 2022 7:58 pm
by magnussandstrom
Thanks Jimmy, but unfortunatly I do not have the scripting module.

What I need is to just copy the text from the html-file and insert as PrivateData, but maybe thats not possible without the scripting module?

Maybe someone can build the app: 'Text file 2 PrivateData'

Re: HTML-table as variable in HTML-mail?

Posted: Wed Nov 30, 2022 10:27 pm
by Padawan
Are you on windows or mac?

Re: HTML-table as variable in HTML-mail?

Posted: Thu Dec 01, 2022 6:51 am
by magnussandstrom
Padawan wrote: Wed Nov 30, 2022 10:27 pm Are you on windows or mac?
Windows

Re: HTML-table as variable in HTML-mail?

Posted: Thu Dec 01, 2022 8:49 am
by Padawan
You can use the "Run Command" App to achieve this. You can use either Cmd or PowerShell:

In Cmd using the type command:
Screenshot 2022-12-01 at 08.46.58.png
Screenshot 2022-12-01 at 08.46.58.png (46.56 KiB) Viewed 7837 times

In powershell using the Get-Content command:
Screenshot 2022-12-01 at 08.47.06.png
Screenshot 2022-12-01 at 08.47.06.png (46.55 KiB) Viewed 7837 times
The path to the text file can be set via variables of course. The content will be in the FileContent Private Data field.

Re: HTML-table as variable in HTML-mail?

Posted: Thu Dec 01, 2022 9:05 am
by JimmyHartington
Padawan wrote: Thu Dec 01, 2022 8:49 am You can use the "Run Command" App to achieve this. You can use either Cmd or PowerShell:
This was a clever way to do it. :D

Re: HTML-table as variable in HTML-mail?

Posted: Thu Dec 01, 2022 11:45 am
by Padawan
Thanks! The solution is not very elegant, but it works :)

Re: HTML-table as variable in HTML-mail?

Posted: Thu Dec 01, 2022 12:20 pm
by magnussandstrom
Padawan wrote: Thu Dec 01, 2022 8:49 am You can use the "Run Command" App to achieve this.
Thanks, it works great!

I ended up using Command Promt and command:

Code: Select all

type "%%InputFilePath%%"

Re: HTML-table as variable in HTML-mail?

Posted: Fri Dec 02, 2022 4:26 pm
by Shawn_Anderson
Yeah the Run Command app is great for parsing text files into private data. I use these on the Mac in the zsh shell all the time

to read all the text

Code: Select all

cat %%InputFilePath%%
to read just the first line

Code: Select all

head -1 %%InputFilePath%%
to read everything after the first line

Code: Select all

tail -n +2 "%%InputFilePath%%"
to read lines that contain the string 'keyword'

Code: Select all

awk '/keyword/{print}' "%%InputFilePath%%"