Send TYPO3 EXT:powermail mail to different receivers depending on selection in a dropdown - typo3

I often have the requirement to send a powermail-form to different receivers depending on a selection of a selectfield within the form.
Im using TYPO3 7.6.x and Powermail 3.3.0
How can this be done?

With the help of #alex-kellner in the slackchannel of EXT:powermail i found a quite easy solution for that:
Basically there are 2 Steps needed:
Step1
Values for the Options in the select field.
You need to add values to your option in the select field. This can be done by appending a pipe | to your option and simply add the value
MyRecieverEmail 1 | 1
MyRecieverEmail 2 | 2
MyRecieverEmail 3 | 3
In addition to that, you need to know the marker / variable / individual fieldname of your field. You can find that name in the extended tab of your field.
You can also give this field an "own" variable name if needed. The variable is wrapped with {} but you will not these in step 2
Step 2
Now you need to add some TS in your setupfield.
Background information: Basically this changes the reciever for a form:
plugin.tx_powermail.settings.setup.receiver.overwrite.email = TEXT
plugin.tx_powermail.settings.setup.receiver.overwrite.email.value = your#email.com
Now you need to check wich option was choosen in the form. This is done by a global condition:
[globalString = GP:tx_powermail_pi1|field|yourVariableFieldname = 1]
Where yourVariableFieldname ist the individual fieldname from the extended tab in the field and 1 is the value of the first option (MyRecieverEmail 1)
By using this TS, the form will be send to your#email.com if the first option MyRecieverEmail 1 is choosen in the form:
[globalString = GP:tx_powermail_pi1|field|yourVariableFieldname = 1]
plugin.tx_powermail.settings.setup.receiver.overwrite.email = TEXT
plugin.tx_powermail.settings.setup.receiver.overwrite.email.value = your#email.com
[global]
You can now add as much conditions as you need. The complete example would be:
[globalString = GP:tx_powermail_pi1|field|yourVariableFieldname = 1]
plugin.tx_powermail.settings.setup.receiver.overwrite.email = TEXT
plugin.tx_powermail.settings.setup.receiver.overwrite.email.value = yourfirst#email.com
[global]
[globalString = GP:tx_powermail_pi1|field|yourVariableFieldname = 2]
plugin.tx_powermail.settings.setup.receiver.overwrite.email = TEXT
plugin.tx_powermail.settings.setup.receiver.overwrite.email.value = yoursecond#email.com
[global]
[globalString = GP:tx_powermail_pi1|field|yourVariableFieldname = 3]
plugin.tx_powermail.settings.setup.receiver.overwrite.email = TEXT
plugin.tx_powermail.settings.setup.receiver.overwrite.email.value = yourthird#email.com
[global]
Please be aware that this will be in charge for every field with the fieldname {yourVariableFieldname} in your TYPO3-Install where this TS is taken into account.
This can be useful if you use this field exactly like this in multiple forms.
If you dont want this to be in charge you have 2 options to avoid this:
only place the TS on the Page where your form is located.
You can add this to your global condition:
&& [globalString = GP:tx_powermail_pi1|mail|form = 123]
Where 123 is the ID of your form.
This would then look like this:
[globalString = GP:tx_powermail_pi1|field|yourVariableFieldname = 2] && [globalString = GP:tx_powermail_pi1|mail|form = 123]

Since 9.5 something like this:
[traverse(request.getParsedBody(), 'tx_powermail_pi1/field/yourVariableFieldname') == 1 ]
should works

This worked for me:
[traverse(request.getParsedBody(), 'tx_powermail_pi1/field/yourVariableFieldname') == 1 ]
plugin.tx_powermail.settings.setup {
receiver.overwrite {
email.value = MYEMAIL
email = TEXT
}
}
[END]
[traverse(request.getParsedBody(), 'tx_powermail_pi1/field/yourVariableFieldname') == 2 ]
plugin.tx_powermail.settings.setup {
receiver.overwrite {
email.value = MYEMAIL2
email = TEXT
}
}
[END]

Related

Google script - send email alert

I have a script that looks into values in column G and if the correspondent cell in column A is empty, sends me an email.
--- WHAT WORKS --
It works ok for static values: it sends one email per each not empty cell in column G for which there is no value in column A
--- WHAT DOESN'T WORK --
It sends several emails for what I assume it's every Column G cell (empty or not) when the column A values are fetched from another tab. That way it's like all G and A cells have data, so I get multiple unwanted emails.
This is the script code:
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName('Sheet to send emails');
const data = sh.getRange('A2:G'+sh.getLastRow()).getValues();
data.forEach(r=>{
let overdueValue = r[0];
if (overdueValue === ""){
let name = r[6];
let message = 'Text ' + name;
let subject = 'TEXT.'
MailApp.sendEmail('myemail#gmail.com', subject, message);
}
});
}
And this is the link to the test sheet:
https://docs.google.com/spreadsheets/d/1OKQlm0PjEjDB7PXvt34Og2fa4vPZWnvLazTEawEtOXg/edit?usp=sharing
In this test case, I "should" only get one email, related to ID 55555. With the script as is, I get one related to 55555 and several others "undefined".
To avoid e-mail spam, I didn't add the script to that sheet but it shows the "Vlookup" idea.
Can anyone give me a hand, please?
Thank you in advance
Issue:
The issue with your original script is that the sh.getLastRow returns 1000 (it also processes those rows that doesn't have contents, result to undefined)
Fix 1: Get specific last row of column G:
const gValues = sh.getRange('G1:G').getValues();
const gLastRow = gValues.filter(String).length;
or
Fix 2: Filter data
const data = sh.getRange('A2:G' + sh.getLastRow()).getValues().filter(r => r[6]);
Note:
As Kris mentioned in the comments, there is a specific case where getting the last row above will fail (same with getNextDataCell). This will not properly get the last row WHEN there are blank rows in between the first and last row of the column. If you have this kind of data, then use the 2nd method which is filtering the data.
If your data in column G does not have blank cells in between the first and last row, then any method should work.
I checked your test sheet, and sh.getLastRow() is 1000.
OPTION 1
If column G won't have empty cells between filled ones, then you can do this:
const ss = SpreadsheetApp.getActive();
const sheet = ss.getSheetByName("Sheet to send emails");
// get the first cell in column G
var gHeader = sheet.getRange(1, 7);
// equivelent of using CTRL + down arrow to find the last da
var lastRow = gcell.getNextDataCell(SpreadsheetApp.Direction.DOWN).getRow();
const data = sheet.getRange(2, 1, lastRow, 7).getValues();
OPTION 2
Add another condition to your code - like this:
data.forEach(r=>{
let overdueValue = r[0];
let name = r[6]
// check if the value in col A is blankd and col G is not blank
if (overdueValue === "" && name !== ""){
let message = 'Text ' + name;
let subject = 'TEXT.'
MailApp.sendEmail('myemail#gmail.com', subject, message);
}
});
And to speed it up, use a named range to limit how many rows it has to iterate through:
const ss = SpreadsheetApp.getActive();
const data = ss.getRangeByName("Your_NamedRange_Here").getValues();

count with an input from user in Terraform?

I want to create a number of resources using terraform depending which number the user enters. The number have to be between 2 and 5.
I tried:
in vars.tf:
variable "user_count" {
type = number
default = 2
description = "How many number of VMs to create (minimum 2 and no more than 5): "
}
The problem here is its creates the resources with the default number 2.
Another case:
variable "user_count" {
type = number
description = "How many number of VMs to create (minimum 2 and no more than 5): "
}
Here, without the default parameter. I get the message/description, but I/the user can enter anything!
How to make this possible? - the user get a message and verify the number is between 2 and 5, else the resources will not be created.
Any help is appreciate - I am really stuck in it!
You may try custom validation
variable "user_count" {
type = number
description = "How many number of VMs to create (minimum 2 and no more than 5): "
validation {
condition = var.user_count > 1 && var.user_count < 6
error_message = "Validation condition of the user_count variable did not meet."
}
}
But maybe better option instead of checking number, will be variable as string and regex to check if value is 2,3,4 or 5.
variable "user_count" {
type = string
description = "How many number of VMs to create (minimum 2 and no more than 5): "
validation {
# regex(...) fails if it cannot find a match
condition = can(regex("2|3|4|5", var.user_count))
error_message = "Validation condition of the user_count variable did not meet."
}
}

Get Row and Column number from "ThisComponent.CurrentSelection" in libreoffice calc basic

I have this code where I can get which one is the current selected cell and use it to modify its value:
theSelection = ThisComponent.CurrentSelection
theSelection.setString("some value")
Now I want to move to the next column to the right, if it was Microsoft excel VBA I could just use something like theSelection.Offset(0,1) but that's not the case. So I'm doing some workarounds of course:
nextCell = oActiveSheet.getCellByPosition( ???currentColumn + 1, ???currentRow)
ThisComponent.CurrentController.select( nextCell )
I just want to know the simplest way to replace these ??? to the actual values of the theSelection var to move to the next column to the right.
I also tried this:
nextCell = oActiveSheet.getCellByPosition( column() + 1, row())
But I don't know why it is always returning column() = 1 and row() = 1 in regardless of which is the value of the CurrentSelection. Thanks in advance for the help.
Get the cell address.
Sub ChangeAndThenGoToCellToRightOfSelection
oActiveSheet = ThisComponent.getCurrentController().getActiveSheet()
oSels = ThisComponent.getCurrentSelection()
If oSels.supportsService("com.sun.star.sheet.SheetCell") Then
'A single cell is selected.
oSels.setString("some value")
address = oSels.getCellAddress()
nextCell = oActiveSheet.getCellByPosition(address.Column + 1, address.Row)
ThisComponent.CurrentController.select(nextCell)
End If
End Sub
To see what an object can do, use an introspection tool such as XrayTool or MRI.

TYPO3: Condition "if column empty"?

I'm looking for a condition to check wether a certain column is empty.
Something like this:
[colPos.0 = empty]
#do stuff
[global]
Thanks in advance.
Edit:
I think it's quite unclear what I'm looking for. So let me add some information:
I've got a column for a teaser image in the BE (colPos = 0). If it contains an element, it should regularly display this element. If not (== if empty), it should use another image instead.
There is of course a possibility to show stuff wether a Column has content or not,
but there is no TS-condition for this.
based on https://kuttler.eu/en/post/change-template-if-content-exists-in-typo3/,
here is my solution for this:
temp.foo {
temp.foo = COA
10 = COA
10 {
10 < styles.content.get
10.select.where = colPos=1
# conditional to test if content exists in column
if.isTrue.numRows {
# check current page page
pidInList = this
# in the table tt_content
table = tt_content
# colPos = 1
select.where = colPos=1
}
}
20 = COA
20 {
10 < lib.somethingElse
# conditional to test if content exists in column
if.isFalse.numRows {
# check current page page
pidInList = this
# in the table tt_content
table = tt_content
# colPos = 1
select.where = colPos=1
}
}
}
if.isTrue and if.isFalse are doing the trick here.
HTH
You can use if function, sample (from doc):
page.10 = COA_INT
page.10.10 = TEXT
page.10.10 {
stdWrap.if.isNull.field = description
value = No description available.
}
Edit: Also, if you are using Fluid template, you can just use f:if condition.

How to automatically generate sequent numbers when using a form

Ahab stated in 2010: the complex looking number based on the Timestamp has one important property, the number can not change when rows are deleted or inserted.
As long as the submitted data is not changed by inserting deleting rows the simple formula =ArrayFormula(ROW(A2:A) - 1) may be the easiest one to use.
For other situations there is no nice reliable solution. :(
Now we live in 2015. Maybe times have changed?
I need a reliable way to number entries using a form.
Maybe a script can do the trick? A script that can add 1 to each entry?
That certain entry has to keep that number even when rows are deleted or inserted.
I created this simple spreadsheet in which I added 1,2, and 3 manually,please have a look:
https://docs.google.com/spreadsheets/d/1H9EXns8-7m9oLbCrTyIZhLKXk6TGxzWlO9pOvQSODYs/edit?usp=sharing
The script has to find the maximum of the former entries, which is 3, and then add 1 automatically.
Who can help me with this?
Grtz, Bij
Maybe a script can do the trick? A script that can add 1 to each
entry?
Yes, that would be what you need to resort to. I took the liberty of entering this in your example ss:
function onEdit(e) {
var watchColumns = [1, 2]; //when text is entered in any of these columns, auto-numbering will be triggered
var autoColumn = 3;
var headerRows = 1;
var watchSheet = "Form";
var range = e.range;
var sheet = range.getSheet();
if (e.value !== undefined && sheet.getName() == watchSheet) {
if (watchColumns.indexOf(range.getColumn()) > -1) {
var row = range.getRow();
if (row > headerRows) {
var autoCell = sheet.getRange(row, autoColumn);
if (!autoCell.getValue()) {
var data = sheet.getDataRange().getValues();
var temp = 1;
for (var i = headerRows, length = data.length; i < length; i++)
if (data[i][autoColumn - 1] > temp)
temp = data[i][autoColumn - 1];
autoCell.setValue(temp + 1);
}
}
}
}
}
For me the best way is to create a query in a second sheet pulling everything from form responses in to second column and so on. then use the first column for numbering.
In your second sheet B1 you would use:
=QUERY(Form!1:1004)
In your second sheet A2 you would use:
=ARRAYFORMULA(if(B2:B="",,Row(B2:B)-1))
I made a second sheet in your example spreadsheet, have a look at it.