# Reference Tag Create Script

**URL:** <https://forum.inductiveautomation.com/t/reference-tag-create-script/97869>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [October 29, 2024, 4:21am UTC](https://forum.inductiveautomation.com/t/reference-tag-create-script/97869 "2024-10-29T04:21:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_DeLuca](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Matthew\_DeLuca](https://forum.inductiveautomation.com/u/Matthew_DeLuca)\
**Post date:** [October 29, 2024, 4:21am UTC](https://forum.inductiveautomation.com/t/reference-tag-create-script/97869/1 "2024-10-29T04:21:43Z")

</div>

Is there a way to use `system.tag.configure` or `system.tag.addTag` to create a reference tag?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 29, 2024, 11:09am UTC](https://forum.inductiveautomation.com/t/reference-tag-create-script/97869/2 "2024-10-29T11:09:06Z")

</div>

Yes, with `system.tag.configure`, by including the `valueSource` property.

---

<div class="post-metadata">

**Author:** ![Matthew\_DeLuca](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Matthew\_DeLuca](https://forum.inductiveautomation.com/u/Matthew_DeLuca)\
**Post date:** [October 29, 2024, 1:33pm UTC](https://forum.inductiveautomation.com/t/reference-tag-create-script/97869/3 "2024-10-29T13:33:08Z")

</div>

I have not had any luck trying that. I also tried `system.tag.addTag` but a reference tag is not listed in the documentation.

```python
# Define the path for the new reference tag
targetFolderPath = "[default]Dev_DeLuca"
# Define the name of the new reference tag
newTagName = "ReferenceToTest"
# Define the source tag path to reference
sourceTagPath = "[default]Dev_DeLuca/Test"

# Complete the full path of the new reference tag
targetTagFullPath = "{}/{}".format(targetFolderPath, newTagName) # Using .format() instead of f-string
print targetTagFullPath

# Check if the reference tag already exists
if not system.tag.exists(targetTagFullPath):
    # Configure the reference tag
    tagConfig = {
        "name": newTagName,
        "tagType": "Reference",
        "valueSource": "Reference",
        "sourceTagPath": sourceTagPath
    }

    # Use system.tag.configure to create the new reference tag
    result = system.tag.configure(targetFolderPath, [tagConfig], "o") # "o" = overwrite if it doesn't exist
    print("Reference tag created:", result)
else:
    print("Reference tag already exists at:", targetTagFullPath)

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/a/da6a5b4a3487b250741a6cdb159c4d4a982b7090.png)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [October 29, 2024, 1:43pm UTC](https://forum.inductiveautomation.com/t/reference-tag-create-script/97869/4 "2024-10-29T13:43:06Z")

</div>

The tag type should be AtomicTag not Reference. I also believe you can just not include it as the valueSource property is enough to identify it as a reference tag.

If you're ever in doubt, you can create a reference tag using the UI, and then use `system.tag.getConfiguration()` it will show you these kinds of things.

---

<div class="post-metadata">

**Author:** ![Matthew\_DeLuca](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Matthew\_DeLuca](https://forum.inductiveautomation.com/u/Matthew_DeLuca)\
**Post date:** [October 29, 2024, 1:58pm UTC](https://forum.inductiveautomation.com/t/reference-tag-create-script/97869/5 "2024-10-29T13:58:52Z")

</div>

Thank you for the feedback, I got the below to work. I had to add some additional properties.

```python
system.tag.getConfiguration("[default]Dev_DeLuca/Test 1")

# Define the path for the new reference tag
targetFolderPath = "[default]Dev_DeLuca"
# Define the name of the new reference tag
newTagName = "ReferenceToTest"
# Define the source tag path to reference
sourceTagPath = "[.]Test"

# Complete the full path of the new reference tag
targetTagFullPath = "{}/{}".format(targetFolderPath, newTagName) # Using .format() instead of f-string

# Check if the reference tag already exists
if not system.tag.exists(targetTagFullPath):
    # Configure the reference tag
    tagConfig = {
        "name": newTagName,
        "tagType": "AtomicTag",
        "dataType": "String",
        "valueSource": "reference",
        "sourceTagPath": sourceTagPath
    }

    # Use system.tag.configure to create the new reference tag
    result = system.tag.configure(targetFolderPath, [tagConfig], "o") # "o" = overwrite if it doesn't exist
    print("Reference tag created:", result)
else:
    print("Reference tag already exists at:", targetTagFullPath)
print sourceTagPath

```
