Removing link back from the created note to the original note

I have a note called “Note’ in my root. The “Note” has an attribute called “$Term”. When I add a term e.g. Lonon, to $Term and run the following stamp, it create a new note called “London” in my Resources container and links it back to “Note”. The stamp works well for creating and making a link.

However, when I remove the term (e.g. London) from the $Term, and run the Stamp, the link from London to “Note” still persists. How can I remove this link (back to “Note”) but, preserve the note “London” (i.e. not to delete it), when a term (e.g. London) is removed from the $Term in the “Note”. Thank you.

var:string vCont=“/Resources Notes/”;
var:string vNote;
var:string vPath;

// Pass 1: Remove links to Resource notes no longer in $Term
collect(vCont).each(n){
vNote = $Name(n);
if(!$Term.contains(vNote)){
unlinkTo(n);
};
};

// Pass 2: Create notes and link for current $Term members
$Term.each(x){
vNote = x;
vPath = vCont + vNote;
create(vPath);
linkTo(vPath);
};

If you have a list of all values of $Term, you could easily make a list of all values of $Term that this note does not have. London is now one of those. Then, step through this list and unlink each of the possible destinations.

Alternatively, step through eachLink from this note, and if its destination is a term, unlink that term.

@eastgate Thank you! Will do.