I have the custom code below that I can’t get to work with Substring.
I can get the partNum and then display it in a message fine, but if I use partNum.Substring(0,5) I get an error at that point. If I hardode partNum and then use Substring the code works perfectly fine. Error is: ‘NullReferenceException’
Seems very odd.
var jobNum = ipJobNum;
var mill = "Mill 2";
var jobHead_xRow = (from JobHead_Row in Db.JobHead where JobHead_Row.JobNum == jobNum select JobHead_Row).FirstOrDefault();
string partNum = jobHead_xRow.PartNum;//Throws error when using Substring below partNum = "F1016CR0I";//Works
Probably a case of where the string isnt 5 chars long… like if its blank. I notice you arent filtering your rows for only added\updated (which means there may be records you arent aware of)
var jobHead_xRow = (from JobHead_Row in Db.JobHead where JobHead_Row.JobNum == jobNum select JobHead_Row).FirstOrDefault();
You could do that, or simply do a length check of the string first
The part number is always the same length 9 characters. I will double check the added or updated. This is in Labor. CheckEmployeeActivity so it is using the input paramater jobNum from start activity.
Ah, I went back and re-read, I misunderstood. check that jobHead_Row is not null first. Is it possible this is called before the job is created? What method is this? Pre or Post?
I started from scratch and it is working now.
What was odd is that I had using for System.IO and System.Text, however it would say it was missing so I had to type it all in my code. After starting from scratch my using statements are working also.