Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation - Updating an existing macro/trigger/automation #514

Open
tobenary opened this issue Jun 2, 2022 · 0 comments
Open

Documentation - Updating an existing macro/trigger/automation #514

tobenary opened this issue Jun 2, 2022 · 0 comments

Comments

@tobenary
Copy link

tobenary commented Jun 2, 2022

Please add the below information to your documentation quick start, it will ease for new developers.

In order to update an existing macro/trigger/automation, those steps needs to be done:

  1. Creating an empty list of actions
  2. Appending the current actions and if we need a change, adding it to the list we created in step1.
  3. Update the actual macro with the content of the new list.
  4. Perform the actual Zendesk update.

In this example, I changed the placeholder {{ticket.assignee.name}} to be {{current_user.name}}.

from zenpy.lib.api_objects import Macro

for macro in zenpyclient.macros():
    macro_update = Macro(
        actions=[]
    )
    for action in macro.actions:
        if 'assignee.name}}' in action['value'] and macro.active:
            macro_update.actions.append(
                {"field": action["field"], "value": action['value'].replace('{{ticket.assignee.name}}', '{{current_user.name}}')}
            )
        else:
            macro_update.actions.append(
                {"field": action["field"], "value": action["value"]}
            )
    if str(macro.actions) != str(macro_update.actions):
        print(macro.title, macro.id)
        macro.actions = macro_update.actions
        d = zenpyclient.macros.update(macro)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant