I can't get it to work either. The script works as expected when copy-pasted into the Python window, but when run as a script, it doesn't apply the join.
Below is the script I modified to try and get it to work (but it did not):
import arcpy
in_layer_name = 'Alpha'
join_table = 'C:\\Users\\dblanchard\\Desktop\\Python_Join\\Default.gdb\\Beta'
join_field = 'JID'
# Get the currently active map
aprx = arcpy.mp.ArcGISProject('CURRENT')
map = aprx.activeMap
# Get the in layer from the map
in_layer_list = map.listLayers(in_layer_name)
if len(in_layer_list) == 1:
in_layer = in_layer_list[0]
arcpy.management.AddJoin(in_layer, join_field, join_table, join_field, "KEEP_ALL")
aprx.save()
else:
arcpy.AddError('Found {} layers matching the "{}" name when only 1 was expected.'.format(len(in_layer_list), in_layer_name))
I also experienced this issue when using ModelBuilder. It works if I run it with the model open, but if I close the model and run it from the toolbox, it doesn't apply the join.
I would suggest you log a support ticket if you have access to Esri Support. Unfortunately, I cannot log a support ticket on your behalf.
A workaround which may be suitable for you is to use a Task. I have a tried a simple task which has the Add Join tool in it and it works as expected.