Method Directive C# Code Error - Help Needed

We are trying to write up a BPM that will take information entered when creating a new Vendor and populate the UD05 table. Below is the code I am using to populate UD05:



/* Finds required ud code types  */
using (var txScope = IceContext.CreateDefaultTransactionScope())
{    
foreach (var UDCodeTypeFound in (from row in Db.UDCodeType where row.Company == Session.CompanyID && (row.CodeTypeID == "SupCustApp" || row.CodeTypeID == "SupRegApp" ) select row))
        {
        /* Finds all ud codes related to the selected ud types */
        foreach (var UDCodeFound in (from row in Db.UDCodes where row.Company == Session.CompanyID && row.CodeTypeID == UDCodeTypeFound.CodeTypeID && row.IsActive == true select row))
            {
          
          /* Update UD Record */
         UD05 newRow = new UD05();
         Db.UD05.Insert(newRow);
         newRow.Company = Session.CompanyID;
         newRow.Key1 = VendorNum_c;
         newRow.Key2 = UDCodeTypeFound.CodeTypeID;
         newRow.Key3 = UDCodeFound.CodeID;

         newRow.CheckBox01 = false;
         newRow.ShortChar01 = UDCodeFound.CodeID;
                       
   
            }
        }
Db.Validate();
txScope.Complete();

}

The method directive selected is Vendor > Update method and has a condition statement in place to catch whether the line updated is an added line or an updated one. I have troubleshot down through using message boxes and the BPM appears to follow the correct logic down to the C# code where we get the following error:

Based on that error I went to look at line 33 only to realize that there are only 31 lines of code. Then I thought to look at line 17 based on column 17 listed but couldn’t find any error on that line either. Does anyone have a method as to decypher what this error is actually looking at, and why it seems to be so angry?

I also tested to make sure that removing the c# code would allow the system to flow as intended, which it does. So the error is defiantly within the custom code. I have used this chunk of code in the past to write things to other ud tables but it works fine in those instances.

I have had similar problems in the past with the correct line number… that I believe is because there may be lines inserted before your actual code.
To figure out which line is the “real” line 33, I would insert a new line at the top of the code that would force an error such as:

var errorout = 1 / 0; //this WILL error out

THEN you run this BPM and you will now know what line you are working with… if you put this as the first line in your BPM, but the error message says that it was line 10, then you know there is a 10 line offset.

2 Likes

Seriously that got me right to the root of my problem. It was with the second iterator statement. @timshuwy when you get a hot minute please compile your wisdom into a word document. I’m more than willing to pay!

2 Likes

Just many years of experience in old-school programming. Glad I could help.

The good news is that you don’t have to pay… just post the questions here and someone will typically answer. We have lots of willing experts ready to expound on the easiest ways to do something.

2 Likes