Hi everyone,
I recently discovered something strange with arcpy.GetParameterAsText() in a script tool. If the function is used after arcpy.ExcelToTable_conversion, somehow it will not receive any value from the toolbox.
I managed to reproduce this behaviour with the simplest script here.
import arcpy,os
if __name__ == '__main__':
param1 = arcpy.GetParameterAsText(0) #gdb
param2 = arcpy.GetParameterAsText(1)
in_excel = r"E:\Python\ghzrzyw_202209\script\new.xlsx"
fgdb = r"D:\Documents\ArcGIS\Default.gdb"
out_table = os.path.join(fgdb, "testtable")
arcpy.env.workspace = fgdb
arcpy.env.OverwriteOutput = True
sheet = "test"
arcpy.ExcelToTable_conversion(in_excel, out_table, sheet)
param3 = arcpy.GetParameterAsText(2)
param4 = arcpy.GetParameterAsText(3)
arcpy.AddMessage(param1)
arcpy.AddMessage(param2)
arcpy.AddMessage(param3)
arcpy.AddMessage(param4)
The messages printed out only contain param 1 and 2.
Param 3 and 4 are NoneType values based on my further test, even though I provided some values as input. This happens regardless of the parameter data types configured with the script tool.

if I shift arcpy.ExcelToTable_conversion to after all the arcpy.GetParameterAsText(), then it all works fine. So it would seem that whether arcpy.GetParameterAsText is placed is the main culprit here.
My questions:
- Is this an expected behaviour? I'm using ArcMap 10.8.1.
- If so, does it mean that it's always recommended to use arcpy.GetParameterAsText() at the start of the script?
Thanks in advance!