Ankur Bawiskar
Tera Patron

@tom the 

that's because subcategory is dependent on category

I hope you are setting the correct subcategory for the category you are setting via script.

give some timeout like 2-3 seconds and then set subcategory

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader