Let's say I need to add a new statement to an existing Def query to all layers in a group which would like like something like this:
aprx <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"CURRENT"</SPAN><SPAN class="punctuation token">)</SPAN>
m <SPAN class="operator token">=</SPAN> aprx<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Map"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">for</SPAN> lyr <SPAN class="keyword token">in</SPAN> m<SPAN class="punctuation token">.</SPAN>listLayers<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> lyr<SPAN class="punctuation token">.</SPAN>supports <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"longname"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
parent <SPAN class="operator token">=</SPAN> lyr<SPAN class="punctuation token">.</SPAN>longName<SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'\\'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> parent <SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"Group"</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN>lyr<SPAN class="punctuation token">.</SPAN>longName<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> lyr<SPAN class="punctuation token">.</SPAN>supports<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"DEFINITIONQUERY"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
oldDefQuery <SPAN class="operator token">=</SPAN> lyr<SPAN class="punctuation token">.</SPAN>definitionQuery
lyr<SPAN class="punctuation token">.</SPAN>definitionQuery <SPAN class="operator token">=</SPAN> None
newDefQuery <SPAN class="operator token">=</SPAN> oldDefQuery <SPAN class="operator token">+</SPAN> <SPAN class="string token">" CODE = 0"</SPAN>
lyr<SPAN class="punctuation token">.</SPAN>definitionQuery <SPAN class="operator token">=</SPAN> newDefQuery<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
What happens after running the script is that the old definition query becomes inactive and the newly created query is added and becomes active. However they both remain the same query name and seem to clash with each other so that no feature pass through the query (don't mind the fieldnames):

There seem to be no detailed explanation on the definitionQuery property at Layer—ArcPy | ArcGIS Desktop
So the questions are:
- How to achieve this to work properly:
- Modify the existing one? - This used to work in ArcMAP
- Remove the initial query completely and place a new modified query?
- Is there any documentation on how to control the functions in the definition query tab on layer properties via Arcpy??

Thanks heaps!