# execute macro in a package when the macro name is variable

**URL:** <https://discourse.getdbt.com/t/execute-macro-in-a-package-when-the-macro-name-is-variable/19880>\
**Category:** Help\
**Created:** [July 17, 2025, 3:46pm UTC](https://discourse.getdbt.com/t/execute-macro-in-a-package-when-the-macro-name-is-variable/19880 "2025-07-17T15:46:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pebbles](https://avatars.discourse-cdn.com/v4/letter/p/f4b2a3/32.png) [@pebbles](https://discourse.getdbt.com/u/pebbles)\
**Post date:** [July 17, 2025, 3:46pm UTC](https://discourse.getdbt.com/t/execute-macro-in-a-package-when-the-macro-name-is-variable/19880/1 "2025-07-17T15:46:14Z")

</div>

Any ideas how to execute macro in a shared package (data\_ops\_shared\_macros) in the project where the macro name is variable:

{% set macro\_name = “data\_ops\_shared\_macros.” ~ this.name ~ “\_json” %}  
{% set current\_model\_macro = context.get(macro\_name) %}

I also tried:  
{% set macro\_name = this.name ~ “\_json” %}  
{% set macro\_name = “macros.data\_ops\_shared\_macros.” ~ this.name ~ “\_json” %}  
{% set macro\_name = “data\_ops\_shared\_macros.macro.” ~ this.name ~ “\_json” %}, and some other random combinations with no luck.

The context returns “None” which means the object was not found in the graph. Works fine when I move the macro to the main project which is not ideal. It should be in shared macros package. Thank you!

---

<div class="post-metadata">

**Author:** ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)\
**Post date:** [July 17, 2025, 3:55pm UTC](https://discourse.getdbt.com/t/execute-macro-in-a-package-when-the-macro-name-is-variable/19880/2 "2025-07-17T15:55:16Z")

</div>

Maybe adapter.dispatch?  
[https://docs.getdbt.com/reference/dbt-jinja-functions/dispatch](https://docs.getdbt.com/reference/dbt-jinja-functions/dispatch)

Note: `@Abigail Green (CHG Healthcare)` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1752767707939089?thread_ts=1752767207.311599&cid=CBSQTAPLG). It might not have transferred perfectly.
