# Templater deletes parts of templater script

**URL:** <https://forum.obsidian.md/t/templater-deletes-parts-of-templater-script/74996>\
**Category:** Help\
**Tags:** templater\
**Created:** [January 15, 2024, 9:58am UTC](https://forum.obsidian.md/t/templater-deletes-parts-of-templater-script/74996 "2024-01-15T09:58:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SiliasOS](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@SiliasOS](https://forum.obsidian.md/u/SiliasOS)\
**Post date:** [January 15, 2024, 9:58am UTC](https://forum.obsidian.md/t/templater-deletes-parts-of-templater-script/74996/1 "2024-01-15T09:58:30Z")

</div>

Hi there,

my templater scripts has two parts (thanks to the explanations of @gino_m in that [thread](https://forum.obsidian.md/t/new-properties-and-templater-prompts-and-commands/66425/27)):

1. adding / updating properties
2. Moving note to specific folder
3. adding a dataview

If I use this templater script I see the following:

- No error message
- the dataview source code
- After (assumable) 0,5 seconds the dataview code gets deleted and the properties are added

My question is:  
Why will the dataview be deleted?

… what is funny:  
If I use this script a second time, on that note, that - now - already has the right properties, the dataview will be added…

# Templater script for library notes

````auto
<%*
// Check if the 'value' tag exists before adding it
setTimeout(() => {
  app.fileManager.processFrontMatter(tp.config.target_file, frontmatter => {
	let key = "aliases"
	let value = ""
	if (!frontmatter[key] || !frontmatter[key].includes(value)) {
      const prop_Array = Array.isArray(frontmatter[key]) ? frontmatter[key] : [];
      if (!prop_Array.includes(value)) {
        prop_Array.push(value);
        frontmatter[key] = prop_Array;
      }
    }
	key = "created"
	value = tp.date.now()
	if (!frontmatter[key] || !frontmatter[key].includes(value)) {
	  const prop_Array = Array.isArray(frontmatter[key]) ? frontmatter[key] : [];
	  if (!prop_Array.includes(value)) {
		prop_Array.push(value);
		frontmatter[key] = prop_Array;
	  }
	}
	key = "tags"
	value = "note/library"
	if (!frontmatter[key] || !frontmatter[key].includes(value)) {
      const prop_Array = Array.isArray(frontmatter[key]) ? frontmatter[key] : [];
      if (!prop_Array.includes(value)) {
        prop_Array.push(value);
        frontmatter[key] = prop_Array;
      }
    }
	delete frontmatter['Unwanted property']
  });
}, 550); // Timeout to allow preceding clipboard operations to complete
_%>
<% await tp.file.move("Atlas/Maps/Library/" + tp.file.title) %>
```dataview
Table tags, file.folder
From #note or "Atlas"
Where contains(Library, [[]])
```

````

Thanks in advance,  
kind regards,

Silias

---

<div class="post-metadata">

**Author:** ![gino\_m](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/g/3ec8ea/32.png) [@gino\_m](https://forum.obsidian.md/u/gino_m)\
**Post date:** [January 16, 2024, 10:06am UTC](https://forum.obsidian.md/t/templater-deletes-parts-of-templater-script/74996/2 "2024-01-16T10:06:29Z")

</div>

I’m not seeing this.  
Try increasing the timeout value maybe.

(Also, as a side note, the word ‘clipboard’ has no meaning here in your use case or comment line.)

---

<div class="post-metadata">

**Author:** ![system](https://forum.obsidian.md/uploads/default/original/3X/b/e/bec35fbd23ab28909bb6bfe62cb32eb82dd34019.png) [@system](https://forum.obsidian.md/u/system)\
**Post date:** [April 15, 2024, 10:07am UTC](https://forum.obsidian.md/t/templater-deletes-parts-of-templater-script/74996/3 "2024-04-15T10:07:14Z")

</div>

Closed on April 15, 2024, 10:07am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
