How to append text to $Text without overwriting

Hi,

I’m trying to create an agent which will add some text to top or bottom of the $text .

I’ve tried doing $text="something"and this overwrite all contents of the note

Did you try $text=$text+“something”?

Attributes names are case-sensitive. No system attribute uses a lower case name. So setting $text does nothing at there is no text attribute (unless you create a user attribute of that name—though I suggest you don’t!).

The attribute you want to set is Text. This sets a note’s Text attribute to some text:

$Text = "This is a sentence.";

To add to (the end of) existing Text, you use code like this:

$Text = $Text + " This more text.";
$Text = $Text + $MyString;

Not I’ve started the the new text entry with a space as this is added to the end of $Text. If you want the added text to be a new paragraph, you need to start with a line return which is entered in code as \n. The line return can be in a literal string, "This is para one.\nThis is para two.". The following both achieve the same result:

$Text = $Text + "\nThis is a new paragraph.";
$Text = $Text + "\n" + "This is a new paragraph.";

The second is simply adding, in sequence two strings to $Text. However, in some circumstances you may find it clearer to read (or laster review). You can use the mathod when adding text from a another attribute:

$Text = $Text + "\n" + $MyString;

The same principles hold if working with any string-based system or user attribute. $Text is a String-type attribute.

Thank you @rkaplan for the answer . I hadn’t

@mwra for your detailed reply as well. Having the example of \n helped clear future doubts as well.

I also get a clear demonstration of agents work continuously(every min) and unless I make my agent query/action conditional , It will keep adding to $Text.

Screenshot 2021-01-20 at 6.30.15 PM

1 Like