I needed to script out a Sql job one Sql server (server1) and use the same script to create the same job on a different Sql server machine(server2). So, I scripted out the job from Server1 and ran the same on the Server2 and got the below error :-
Cannot insert the value NULL into column ‘owner_sid’, table ‘msdb.dbo.sysjobs’
Looking at more closely on the script, I noticed that the the script I created from the job on the Server1 also has the login which I used to login to Server1. This login is different from the one I was using to run the script on server2. See the highlighted login in the below screenshot.
Once I changed the script to put the login I am using to run the script on server2, the script ran fine and the job got created in the Server2.