Method Directive to Create New Record in ShipHead

Good morning Mega-Minds! I’m trying to automatically create a new record in the ShipHead and Detail tables when a user clicks a button on a dashboard. Once the button is clicked, a UD field in the Project table is updated, which triggers this new BPM in the Project/Update BO. The problem is that I’m getting a TargetException error right at the start of the BPM, when trying to create a new record in ShipHead. I have NULL capture code, and am not sure why I’m getting this error. Below is my code, along with the error.

var Proj = ttProject.Where(r => r.Updated()).FirstOrDefault();

if (Proj == null)
return;

string projID = Proj.ProjectID;

// Connect to OrderHed table to get OrderNum
var ordHed = Db.OrderHed.Where(r => r.Company == Proj.Company && r.ProjectID_c == projID).FirstOrDefault();

if (ordHed == null)
return;

// Connect to OrderDtl table
var ordDtl = Db.OrderDtl.Where(r => r.Company == Proj.Company && r.OrderNum == ordHed.OrderNum && r.OrderLine == 1).FirstOrDefault();

if (ordDtl == null)
return;

// Create new record in ShipHead table
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using (var svc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.CustShipSvcContract>())
{
CustShipTableset ts = new CustShipTableset();
svc.GetNewShipHead(ref ts);

foreach (var x in ts.ShipHead.Where(r => r.Added()))
{
x.Company = “Colite”;
x.PackNum = 0;
x.ShipDate = DateTime.Now;
x.ShipViaCode = “BW”;
x.ShipPerson = callContextClient.CurrentUserId;
x.EntryPerson = callContextClient.CurrentUserId;
x.Invoiced = false;
x.ReadyToInvoice = true;
x.CustNum = Proj.ConCustNum;
x.Plant = “MfgSys”;
x.TrackingNumber = “ACCT”;
//x.LegalNumber
x.Voided = false;
x.ExternalDeliveryNote = false;
x.ICReceived = false;
x.BTCustNum = Proj.ConBTCustNum;
x.BTConNum = 0;
x.ShipStatus = “SHIPPED”;
x.Weight = 0;
x.ResDelivery = false;
x.SatDelivery = false;
x.SatPickup = false;
x.VerbalConf = false;
x.Hazmat = false;
x.DocOnly = false;
x.ApplyChrg = false;
x.ChrgAmount = 0;
x.ChangedBy = callContextClient.CurrentUserId;
x.ChangeDate = DateTime.Now;
//x.ChangeTime
x.DeliveryConf = 1;
x.PkgSizeUOM = “FT”;
x.WeightUOM = “OZ”;
x.OTSOrderNum = ordHed.OrderNum;
x.CurrencyCode = “USD”;
x.ShipToCustNum = ordHed.ShipToCustNum;
x.RateGrpCode = “MAIN”;
x.ScheduleNumber = “Schedule Number”;
x.OurBank = “DISB”;
}

svc.Update(ref ts);
}

Thank you for your time any help you can provide! Have a great day.

Not sure if this is a formatting issue in your post, or actually in your code. Doesn’t look like you have curly braces for your IF statements to check for nulls.

Interestingly, I copy+pasta your code and it worked for me without issue!

**Edit–the only difference is I put mine on an In-Trans Data Directive (because that’s what I already had open). Let me try the update BO.

1 Like

I think it’s a format issue that doesn’t show spaces. Those IF statements do not need curly braces if they only have one line. Though it doesn’t show it, the return statement is tabbed over one.

2 Likes

Did you do a Post processing?

I did Pre-Processing.

Worked for me on pre-processing as well. Odd.

1 Like

That’s strange. Maybe I need to restart everything and see if that’s the issue. LOL

Is your new method called “BlockShipping”?
If not, it looks like that could be interferring.

1 Like

It isn’t. That might very well be it.

Your error is referencing an InTran Directive called ProjHold_BlockShipping.
Check that out as that’s what’s causing your error, not your new one.

1 Like

Never seen any code written like that unless it was python. I assumed you were doing something lambda like 1=1 ? dothis : elsedothat; but lambda in my head I thought lambda requires an else.

Its basic things like this that blow me away when I see them for the first time being in the industry for 7 years. I’ve written so many one liners with curly braces…

One liners on if-statements can be done without the curlies, but it’s good practice to include them anyways. Unlike Python, you don’t even need to indent it, but it would look terrible and anyone reading your code after you would probably swear at you. :sweat_smile:
It can be a cause for frustration if you go back and add another line, but forget about the curlies, then wonder why your code is breaking, lol.

2 Likes

Makes sense. I guess this discovery isn’t turning my life upside down anymore like I thought it originally was. Ill quit questioning my life decisions up until this point.

1 Like

I disabled my BlockShipping Data Directive and everything worked fine! I didn’t even think about another directive causing the issue. Thank you for your help! :grinning:

2 Likes