Data Directive C# Array - Help Needed

Im trying to write some custom code for a BPM that is supposed to email purchasers set as default buyers for part class types on a requisition.

What I want this bpm to do is at each requisition line iteration add an entry to an array for the part class. Then I want to have the bpm iterate through the entries of that part class array and populate the second array of default buyer emails. Once the buyer array is populated I want to pull all distinct entries into one the last array. Lastly, I want to iterate through the distinct array and send emails to each entry in that array.

What I need help with is understanding how C# arrays work within Epicor and if there is a way that I can take a count of line items and set the first array to have that many values in it.

Thanks in advance for the help!

Dylan,
Arrays work the same way as anywhere just standard C# array

All you need to do is simply loop through the dataset and add each element to the array, you could use a List<> instead which is an array without a size so you dn’tn have to know the size up front.

3 Likes

@josecgomez,
Here is what I have so far. I need help populating the distinct entries list.

/*START BuyerID ITERATION*/
/*RH = ReqHead*/
var RH = (from r in ttReqHead where r.Added() || r.Updated() select r).FirstOrDefault();
/*List of all part numbers */
List<string> PartClass = new List<string>();
if (RH != null)
{
/*check iterate though all lines listed within the ReqHead.ReqNum entries*/ 
  foreach (var Requisition_iterator in (from r in Db.ReqDetail where r.Company == Session.CompanyID && r.ReqNum == RH.ReqNum select r))
  { 
    if (Requisition_iterator != null)
    {
    var BuyerID = (Db.PartClass.Where( r =>r.Company == callContextClient.CurrentCompany && r.ClassID == Requisition_iterator.Class).Select( r =>r.BuyerID).DefaultIfEmpty("").FirstOrDefault());
    var email = Db.PurAgent.Where( r =>r.Company == callContextClient.CurrentCompany && r.BuyerID == BuyerID).Select( r =>r.EMailAddress).DefaultIfEmpty("").FirstOrDefault();
      PartClass.Add(email);
    }
  }
}  
/*END BUYERID ITERATION*/

/*START EMAIL SORT ITERATION*/
List<string> Emails = new List<string>();
foreach( string k in PartClass)
{
  **Emails.Add(PartClass.Select().Distinct());**
}

/*END EMAIL SORT ITERATION*/

I’m receiving the follow error with the line in ** **:
“No overload for method ‘Select’ takes 0 arguments”

I’m not really sure how to fix that.

You can try this. Select requires that you provide selection parameters so Linq knows which records to get. In this case, you can use Linq to add the distinct values in a simple statement.

The initialization can be simplified to something like var Emails = PartClass.Distinct().

1 Like