# Help needed for scripting OPC tag alarm configuration

**URL:** <https://forum.inductiveautomation.com/t/help-needed-for-scripting-opc-tag-alarm-configuration/93967>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [July 31, 2024, 12:50pm UTC](https://forum.inductiveautomation.com/t/help-needed-for-scripting-opc-tag-alarm-configuration/93967 "2024-07-31T12:50:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Artusito\_FlashLight](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@Artusito\_FlashLight](https://forum.inductiveautomation.com/u/Artusito_FlashLight)\
**Post date:** [July 31, 2024, 12:50pm UTC](https://forum.inductiveautomation.com/t/help-needed-for-scripting-opc-tag-alarm-configuration/93967/1 "2024-07-31T12:50:40Z")

</div>

Hello everyone,

I need your help to create a script that allows me to configure an alarm for an OPC tag and modify its properties. Specifically, the properties I need to be able to modify include:

- Name
- Priority
- Display path
- and other specific properties.

Currently, I managed to create a memory tag from scratch with this script:

```python
# The provider and folder the Tag will be placed at. 
baseTagPath = "[default]MyFolder"
 
# Properties that will be configured on that Tag.
tagName = "myNewTag"
opcItemPath = "ns=1;s=[Simulator]_Meta:Sine/Sine0"
opcServer = "Ignition OPC-UA Server"
valueSource = "opc"
sampleMode = "TagGroup"
tagGroup = "Default"
 
# Configure the tag.
tag = {
            "name": tagName,           
            "opcItemPath" : opcItemPath,
            "opcServer": opcServer,
            "valueSource": valueSource,
            "sampleMode" : sampleMode,
            "tagGroup" : tagGroup
        }
 
# Set the collision policy to Abort. Thus, if a Tag already exists at the base path,
# we will not override the Tag. If you are overwriting an existing Tag, then set this to "o".
collisionPolicy = "a"
 
# Create the Tag.
system.tag.configure(baseTagPath, [tag], collisionPolicy)

```

My problem is that I need to modify an existing tag, not create one from scratch.

Could someone provide an example script or point me in the right direction to develop this? Any suggestions or resources would be greatly appreciated!

Thank you very much in advance!

---

<div class="post-metadata">

**Author:** ![Gokul\_M](https://avatars.discourse-cdn.com/v4/letter/g/e36b37/32.png) [@Gokul\_M](https://forum.inductiveautomation.com/u/Gokul_M)\
**Post date:** [August 2, 2024, 10:40am UTC](https://forum.inductiveautomation.com/t/help-needed-for-scripting-opc-tag-alarm-configuration/93967/3 "2024-08-02T10:40:16Z")

</div>

To modify an existing tag in Ignition, you can use the `system.tag.editTag` function.  
Please check the user manual where you will find example scripts.

> **[system.tag.editTag | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/7.9/appendix/scripting-functions/system-tag/system-tag-editTag)**
>
> Edits an existing Tag in Ignition.

---

<div class="post-metadata">

**Author:** ![Samuel\_Sueur](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Samuel\_Sueur](https://forum.inductiveautomation.com/u/Samuel_Sueur)\
**Post date:** [August 2, 2024, 10:46am UTC](https://forum.inductiveautomation.com/t/help-needed-for-scripting-opc-tag-alarm-configuration/93967/4 "2024-08-02T10:46:56Z")

</div>

`system.tag.editTag` is deprecated in 8.1. Depends which version OP is using.

`system.tag.configure` is better suited.

See below:

> **[7.9 to 8.1 Upgrade Guide | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/getting-started/installing-and-upgrading/ignition-8-upgrade-guide/79to81-upgrade-guide#script-based-tag-editing)**
>
> Ignition 8.1 is a major update across virtually all subsystems and modules. Inductive Automation strives to maintain its commitment to backwards compatibility and a straight-forward upgrade process. However, given the vast scope of changes in 8.1,...

@Artusito_FlashLight have a look at the collisionPolicy argument, and especially use the MergeOverwrite policy, or simple the Overwrite policy:

> **[system.tag.configure | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-configure#parameters)**
>
> Creates tags from a given list of Python dictionaries or from a JSON source string.

---

<div class="post-metadata">

**Author:** ![Artusito\_FlashLight](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@Artusito\_FlashLight](https://forum.inductiveautomation.com/u/Artusito_FlashLight)\
**Post date:** [August 2, 2024, 2:03pm UTC](https://forum.inductiveautomation.com/t/help-needed-for-scripting-opc-tag-alarm-configuration/93967/5 "2024-08-02T14:03:06Z")

</div>

Thanks! Now using the system.tag.configure and this script I can configure the alarm settings of a tag, such as Name, Priority, Label... etc.

```python
tagPath = "[default]MyTag"

currentConfig = system.tag.getConfiguration(tagPath, False)[0]

for alarm in currentConfig.get('alarms', []):
    if alarm['name'] == 'Alarm': # Check the alarm name
        alarm['name'] = 'Test' # Change the alarm name
        alarm['priority'] = 'High' # Change alarm priority
        alarm['label'] = 'Description' # Edit the alarm description
        break

results = system.tag.configure(tagPath.rsplit('/', 1)[0], [currentConfig], 'o')

```

Is there a way in your opinion to be able to use the script to automatically add the alarm to the tag without adding it manually?
