How to shorten a variable in automation?
Asked by Torsten Berger:

Hi there,

in an automation I use {cardname} and additional info for a new card title. Can I shorten the given text? Usually in APIs there is some functionality like for example {cardname\|5} for the first 5 letters ...

Cheers,  
Torsten


Answers:
author: Dreamsuite Mike
body: HI [@Torsten Berger](/t5/user/viewprofilepage/user-id/4973019)

It is worth familiarising yourself with the pattern matching functionality available in Trello:

<https://support.atlassian.com/trello/docs/pattern-matching-and-wildcards/>

using variables like {matchedtext}, {textbeforematch} and {textaftermatch} really help here...

Trello also supports RegEx so you can create more complex examples with that

For example, if you wanted to truncate the card name to 5 characters, the automation would be:
> when the name of a card contains "regex:/\^.{0,5}/", rename the card to {matchedtext}

comments: author: Torsten Berger
body: [@Dreamsuite Mike](/t5/user/viewprofilepage/user-id/5153180) thanks for the hint! But how do get a "when" condition inside my procedure?

My (fake) example (real thing is more complex):

- starts with click to a card button (let's say here on card "Very important Card")

? find a special template card

? copy that template card to list XYZ

? rename title of template to "NEW: {triggercardname}"

? result is a card "NEW: Very important Card"

But as title I only want "New: {first 10 letters from triggercardname}..." (so here "NEW: Very impor...").

I understand regex etc. but for that I would need some "when/if/..." inside my routine and I don't see that. If I just add a find (with cascade ? find card contains "regex:/\^.{0,5}/"), all my cards on the board would get changed.


author: Torsten Berger
body: I solved it somehow with a workaround:

? I created a new rule like "If a specific label is added to a card with name \[here I added the RegEx that finds a very specific prefix and gives me the (*shortened*) part back that I need to rename the later card\]" -- then rename this card to \[here I use the part from the RegEx\]"

? Then I changed the button I described earlier to rename the new card with a specific prefix to the whole name, also I add in the end the specific label, which then triggers the new rule.

So it creates first the card with the whole (long) name (like before) and is then automatically shortened by the new rule. The label is needed to trigger the RegEx-Search to get the part of the whole name. The prefix (in combination with the RegEx) makes sure that not a "normal" card is renamed when the label ist used by accident. I also added a comment with old name - new name, so if someone does trigger it by accident, it can be found and be reversed.

It would be so much easier if Trello would just support some basic template commands, like {triggercardname\|5} would give back the first 5 letters of the name. :-)

Cheers,  
Torsten


author: Dreamsuite Mike
body: Hi [@Torsten Berger](/t5/user/viewprofilepage/user-id/4973019)

Sorry for the delay in replying, I have been travelling.

![Screenshot 2023-09-16 145705.png](https://community.atlassian.com/t5/image/serverpage/image-id/281038i7B2537C952EC4EB8/image-size/large?v=v2&px=999 "Screenshot 2023-09-16 145705.png")

This is the area where you can use "when the name/description of a card contains..."

Regarding the variables, there is almost no chance of Trello making any changes to this so if you do want to do more in that area, it is worth learning around regex. It opens up so many possibilities.

Take a look at this article for guidance:

<https://community.atlassian.com/t5/Trello-articles/Mikes-Trello-Tips-Automation-to-truncate-a-numeric-custom-field/ba-p/2385182>

In that article [@Krimo Khermane](/t5/user/viewprofilepage/user-id/4265376) suggestion of using ChatGPT to formulate the regex query is a really useful tip


Tags: automation