Variables in Text

From Planfix
Jump to: navigation, search

This help article does not apply to document templates. Read how to use variables in document templates here.

Navigation


Variables store some value, such as a number, string, or other data type. Variables are used in:

  • Task name (in task template or when creating a task)
  • Task description (in task template or when creating a task)
  • Email templates
  • Script actions, buttons, incoming webhooks, email rules for tasks:
    • Send HTTP request
    • Send SMS
    • Write to WhatsApp
    • Write to Instagram
  • Bulk actions, scripts, buttons, incoming webhooks, email rules for tasks:
    • Change name
    • Change description
    • Add comment
    • Set field value (for "Text" fields)


To add a variable to the text, for example, in the task description, click on the "different variables" link (1), create the variable, and add it to the text of the desired field in the task template (2):

pXIpIc.jpg


Calculations with Variables

Sometimes, it is not enough to insert the value of a variable into the text, and you also need to do calculations with the values in the variables or process the string you get. For such actions, you use the following syntax:

%%%FORMULA TEXT%%%

Examples

Discounted price: %%%{{Task.Price}}*0.8%%%
Work will be completed in %%%DATEDIF(NOW(); {{Task.Completion Date}}; "d")%%% %%%MULTIPLE(DATEDIF(NOW(); {{Task.Completion Date}}; "d");"day"; "days")%%%

Important

  • The formula text must be written in one string and cannot be broken. In other words, the formula cannot be broken to the next string by pressing the Enter key.
  • Variables in the formula cannot be formatted, for example, changing it to bold or making it cursive.
  • If you need to highlight the result of the formula in bold, apply the formatting to the entire formula along with the result.

IF

To insert text depending on the values of variables (conditions), use the following syntax:

%%$IF(Logical formula)$%%
TEXT
%%$ENDBLOCK$%%

The expression must be added in one string without spaces and line breaks:

%%$IF(Logical formula)$%%TEXT%%$ENDBLOCK$%%

Example

%%$IF({{Task.Order Amount}} > 100000)$%%
VIP CUSTOMER
%%$ENDBLOCK$%%


Result:

VIP CUSTOMER

ELSE

ELSE is used only together with IF. When the condition in IF is not true, the text from the ELSE part of the block is displayed.

%%$IF(Logical formula)$%%
TEXT
%%$ELSE$%%
TEXT
%%$ENDBLOCK$%%

The construction must be added in one line without spaces and line breaks:

%%$IF(Logical formula)$%%TEXT%%$ ELSE$%%TEXT%%$ENDBLOCK$%%

Example

%%$IF({{Task. Invoice №}}="")$%%
The field [Invoice №] is not filled in
%%$ELSE$%%
The required task field is filled in! :)
%%$ENDBLOCK$%%

Result:

  • If the field is not filled in, the message "The field [Invoice №] is not filled in" will be displayed.
  • If the field is filled in, the message "The required task field is filled in! :)" will be displayed.

ELSEIF

Helps create a more complex expression with conditions:

%%$IF(Logical formula)$%%
TEXT
%%$ELSEIF(Logical formula)$%%
TEXT
%%$ELSEIF(Logical formula)$%%
TEXT
%%$ELSE$%%
TEXT
%%$ENDBLOCK$%%


Note

  • The last ELSE is an optional part of the block.

The construction must be added in one line without spaces and line breaks:

%%$IF(Logical formula)$%%TEXT%%$ELSEIF(Logical formula)$%%TEXT%%$ELSEIF(Logical formula)$%%TEXT%%$ ELSE$%%TEXT%%$ENDBLOCK$%%

Example

%%$IF({{Task.Invoice Number}}="")$%%
The field [Invoice Number] is not filled in
%%$ELSEIF({{Task.UPD Number}}="")$%%
The field [UPD Number] is not filled in
%%$ELSEIF({{Task.Contract Number}}="")$%%
The field [Contract Number] is not filled in
%%$ELSE$%%
All task fields are filled in, you're awesome! :)
%%$ENDBLOCK$%%


Result:

  • If all three fields are not filled in, only the first message "The field [Invoice Number] is not filled in" will be displayed, the rest will be skipped.
  • If the fields "Invoice Number" and "UPD Number" are filled in, but the field "Contract Number" is not, then the corresponding message "The field [Contract Number] is not filled in" will be displayed.


FOREACH

When a variable represents a list of values, such as {{Task.Subtasks}} or {{Task.Assignee}}, and you need to display information for each value, use the following syntax:

%%$FOREACH(Variable;Delimiter)$%%
TEXT
%%$ENDBLOCK$%%


Important: in this part of the expression — %%$FOREACH(Variable;Delimiter)$%% — be sure to specify the first-level variable, i.e. {{Task.Subtasks}} or {{Task.Assignee}}, and nothing else.


The expression must be added in one string without spaces and line breaks: %%$FOREACH(Variable;Delimiter)$%%TEXT%%$ENDBLOCK$%%


Example

%%$FOREACH({{Task.Assignee}};"<br>")$%%{{Task.Assignee}} - {{Task.Assignee.Position}}%%$ENDBLOCK$%%


Result:

linda Martinez - Designer
Jamse Davis - Developer
Mary Brown - CEO
%%$FOREACH({{Task.Subtasks}};"<br>")$%%{{Task.Subtasks.Number}} - {{Task.Subtasks.Name}}%%$ENDBLOCK$%%


Result:

2119 - Rough finish
2120 - Sub-final finishing
2121 - Final touches


Example with condition

Syntax:


%%$FOREACH(Variable;Delimiter;Condition_WITHOUT_If)$%%
TEXT
%%$ENDBLOCK$%%


%%$FOREACH({{Task.Subtasks}};"";{{Task.Subtasks."Contract Amount ($)"}}>1000))$%%
{{Task.Subtasks.Counterparty}}, contract amount {{Task.Subtasks."Contract Amount ($)"}}
%%$ENDBLOCK$%%


Result

From the entire list of counterparties, only those with a contract amount of more than 1000 will be displayed:

LLC Sunrise, 1500

LLC Sunset, 1700

LLC Dawn, 2500

ELSE block inside FOREACH block

Syntax:

%%$FOREACH(Variable;Delimiter)$%%
TEXT
 %%$IF(Logical formula)$%%
TEXT
 %%$ENDBLOCK$%%
TEXT
%%$ENDBLOCK$%%


%%$FOREACH({{Task.Subtasks}})$%%%%$IF({{Task.Subtasks.Status}}="TKP added to calculation")$%%
{{Task.Subtasks.Counterparty}}, {{Task.Subtasks.Counterparty.TIN}}, contract amount {{Task.Subtasks."Contract Amount"}} {{Task.Subtasks.Currency.Symbol}}
%%$ENDBLOCK$%%%%$ENDBLOCK$%%


Result:

LLC Sunrise, 5689845987654, 1500 $
LLC Sunset, 5689845125699, 1700 $
LLC Dawn, 5689845589674, 2500 $
LLC Light, 5689845235689, 500 $


TABLE

If a variable represents a list of values, and you need to display the information for each value in the form of a table, use the following syntax:

%%$TABLE(Variable)$%%
TEXT
%%$ENDBLOCK$%%

Example

The example shows how to extract only the necessary blocks from the added data tag in the task and send this information to the customer as a table. The table is added using the Planfix editor:

Order №{{Task.Number}}

%%$TABLE({{Data tag.Service}})$%%

{{Data tag.Service.Service Name}} {{Data tag.Service.Amount}}

%%$ENDBLOCK$%%


Total order amount: %%%TEXT(SUM({{Data tag.Service.Amount}});",.2f")+MULTIPLE(SUM({{Data tag.Service.Amount}}); " ruble"; " rubles")%%%


Result:

Order №2118

Graphic design 1 600.00
Programming 3 000.00
Development of TA 300.00

Total order amount: 4 900.00 dollars


Example with header and total

To add a header or a totals row to the table, use the following parameters in the syntax:

%%$TABLE(Variable;0;0)$%%
Table drawn using the Planfix editor
%%$ENDBLOCK$%%

Example: %%$TABLE({{Data Tag.Service}};0;0)$%%

# Name Price
{{Data tag.Service.Record Number}} {{Data tag.Service.Service Name}} {{Data tag.Service.Amount}}
Total %%%SUM({{Data tag.Service.Amount}})%%%

%%$ENDBLOCK$%%


Result:

# Name Price
1 Development of TA 1 000.00
2 Programming 3 705.00
3 Graphic design 1 035.00
4 Testing 690.00
Total 6430

The numbers highlighted in red indicate how many rows to use in the header and totals.

For example, the numbers (1;1) in the above example mean that one row at the beginning will be used for the table header and one row at the end will be used for the table totals.

To use two rows in the table header, specify it like this — (2;1).

Example: %%$TABLE({{Data tag .Service}};2;1)$%%

Set of services
# Name Price
{{Data tag.Service.Record Number}} {{Data tag.Service.Service Name}} {{Data tag.Service.Amount}}
Total %%%SUM({{Data tag.Service.Amount}})%%%

%%$ENDBLOCK$%%


Result:

Set of services
# Name Price
1 Development of TA 1 000.00
2 Programming 3 705.00
3 Graphic design 1 035.00
4 Testing 690.00
Total 6430

Example with condition

%%$TABLE(Variable;0;0;Condition_WITHOUT_If)$%%
Table drawn using the Planfix editor
%%$ENDBLOCK$%%


%%$TABLE({{Task.Subtasks}};1;0;{{Task.Subtasks.Status}}="TKP added to calculation")$%%

Counterparty TIN Contract amount
{{Task.Subtasks.Counterparty}} {{Task.Subtasks.Counterparty.TIN}} {{Task.Subtasks."Contract Amount"}}{{Task.Subtasks.Currency.Symbol}}

%%$ENDBLOCK$%%


Result:

Counterparty TIN Contract amount
LLC Sunrise 5689845987654 1500$
LLC Sunset 5689845125699 1700$
LLC Dawn 5689845589674 2500$
LLC Light 5689845235689 500$


To add a header to the table, right-click on it and select Row - Insert Row Above:

mTnMq2.jpg


Important

In TABLES at the moment, nesting of constructions is not supported, thus the IF block inside the TABLE will not work. A temporary solution is to use the TABLE block with the IF function, that is, instead of the "%%$IF" block, use the function "%%%IF".

FOREACH and TABLE with infoblocks

When parsing an email or responding to an HTTP request, you receive several lines of data and want to add them in the form of structured text or a table:

%%$FOREACH({{Infoblock.!line}};Separator)$%%
{{Infoblock.!line.Infoblock name}}
%%$ENDBLOCK$%%

%%$TABLE({{Infoblock.!line}})$%%
{{Infoblock.!line.Infoblock name}}
%%$ENDBLOCK$%%


Example

Let's extract data into the "Product" and "Price" infoblocks and add them to the table:

%%$TABLE({{Infoblock.!line}})$%%

{{Infoblock.!string.Product}} {{Infoblock.!string.Price}}

%%$ENDBLOCK$%%

Result:

Pencil 1,00
Pen 2,00
Notebook 10,00

Go To