HTML add variable to string question

I am attempting something that I thought had been previously addressed but can not find the link to it. I am using the exportToHTML in the table component. I want to add another string of HTML to the table component before sending it via email. Here is what I have so far.

table = rootcontainer.getComponent("Table") subject="<html><body><h1>Req. for Parts</h1></body></html>" body = table.exportToHTML("table",1000) sendable=subject + body then I use the fpmi.net.email function and use sendable as what is to be sent

when I add this it works as I expected. However when I want to add a variable to the string above I get an error message about not being able to add, and, or to the string. Here is the revised version that does not work.

the only thing that changes is the subject subject ="<html><body><h1>Req. for Parts</h1><h2>Location:"+mn+"</h2></body></html>"

I have tried the + symbol, the word AND, commas and also tried place str() around the MN even though the MN should already be a string. But each comes back with error messages.

So what simple expression am I missing to add this variable to the string?

Thanks and have a great day.

Please post the error message here.

I think I know the error that you are talking about. Python doesn’t like using the + operator for concatenating (what should be) strings. Try making these changes:

table = rootcontainer.getComponent("Table") subject="<html><body><h1>Req. for Parts</h1></body></html>" body = table.exportToHTML("table",1000) sendable="%s<br>%s</body></html>" %(subject[:-14], body)It’s less complicated than it seems, but %s means ‘insert string here’. The subject[:-14] will give you everything but the last 14 characters of the subject ( needs to be added to the end of the email).

Ok I think we are getting close. Let me explain a little more detail here in hopes of completing this thread.

I have three label fields. All of which are strings. In my code I am calling these strings. The strings are:

Machine: 1, Serial:1011, and just a generic label that the user enters.

If I use the following when the email is sent it is formatted just like I want.

[code]subject="

Req. for Parts.

Machine:1 Serial:1011

" body = table.exportToHTML("table",1000) sendable=subject + body[/code]

When it sends the email it is formatted correctly and the way I want. However where the Machine: and the Serial: is I want the value to be obtained thru a script link. Such as:

mn = rootcontainer.label.getvalue (sorry dont remember the exact structure of this statment)

But serial is obtained the same way. Each mn and sn retrieve the value from the lable located on the root container.

So in the subject= where I currently have a fixed value I want it to substitute the value obtained from the mn= and sn= which are located above the code snippet provided here.

If I understand what you are saying here maybe I can use something like:

[code]subject="

Req. for Parts.

Machine:%s Serial:%s

"%(mn,sn)[/code]

Not sure if this would work being as I am typing from home but would this work or do I also need the
?

Hope this clears things up.

[quote=“Robert.McKenzie”]I think I know the error that you are talking about. Python doesn’t like using the + operator for concatenating (what should be) strings. Try making these changes:

table = rootcontainer.getComponent("Table") subject="<html><body><h1>Req. for Parts</h1></body></html>" body = table.exportToHTML("table",1000) sendable="%s<br>%s</body></html>" %(subject[:-14], body)It’s less complicated than it seems, but %s means ‘insert string here’. The subject[:-14] will give you everything but the last 14 characters of the subject ( needs to be added to the end of the email).[/quote]

That
just mean line break (or newline), so you don’t need it unless you want that formatting. So, assume that there is a label named “label” with 2 dynamic properties (mn and sn), and the button this script is on is in the root container. Then the code will look like this:

[code]mn = event.source.parent.getComponent(“label”).mn
sn = event.source.parent.getComponent(“label”).sn
subject="

Req. for Parts.

Machine:%s Serial:%s

"%(mn,sn) table = rootcontainer.getComponent("Table") body = table.exportToHTML("table",1000) sendable="%s%s" %(subject, body)[/code]