Updating or adding new CustCnt with CustCnAttr

, ,

@hmwillett

You got any ideas on this one?

  CustCntSvcContract custCunt = ServiceRenderer.GetService<CustCntSvcContract>(Db);
  
  var vCustCnt = Db.CustCnt.Where(p =>
                p.Company == Session.CompanyID &&
                p.WebUserUID_c == row.UD02_WebUserUID_c
            ).FirstOrDefault();
  
  int someCustNum = vCustCnt.CustNum; 
  string shipToNum = vCustCnt.ShipToNum;
  int contactNum = vCustCnt.ConNum;

  CustCntTableset ccTS = custCunt.GetByID(someCustNum, shipToNum, contactNum);
     
  CustCntRow ccRow = ccTS.CustCnt.FirstOrDefault();
  
  ccRow.FirstName = "YourVariable";
  ccRow.LastName = "YourVariable";
  ccRow.EMailAddress = "YourVariable";
  ccRow.RowMod = "U";
  
  
  //string[] jobRoles = row.JobRoles_c.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  string pretendingRowOfJobRoles = "I,Drank,Too,Much,Beer";
  List<string> jobRoles = pretendingRowOfJobRoles.Split(",", StringSplitOptions.RemoveEmptyEntries).ToList();
  

  List<string> custCnAttrList = (from attrRows in Db.CustCnAttr
                                   where
                                      attrRows.CustNum == someCustNum &&
                                      attrRows.ShipToNum == shipToNum &&
                                      attrRows.ConNum == contactNum
                                   select
                                      attrRows.AttrCode).ToList();
  
  List<string> addToAttrList = new List<string>(); 
  foreach(string jobRole in jobRoles)
  {
      if(custCnAttrList.Any(attrCode => attrCode == jobRole) == false)
      {
          addToAttrList.Add(jobRole);
      }
  }
  
  ccRow.AttrCodeList = String.Join("~", addToAttrList);  //Is it comma delimited it takes, whatever, you get the gist (Edit, apparently it's a tilde)
  
  custCunt.Update(ref ccTS);
1 Like

Modify to your needs, but this will add a new attribute.

foreach(var tt in queryResultDataset.Results.Where(r=>r.Updated()) )
{
  string newAttrib = tt.Calculated_AddAttrib;
  
  using(var ccBO = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.CustCntSvcContract>(Db))
  {
    CustCntTableset ccTS = new CustCntTableset();
    ccTS = ccBO.GetByID(tt.Customer_CustNum, tt.CustCnt_ShipToNum, tt.CustCnt_ConNum);
    
    CustCntRow newCustRow = new CustCntRow();
    ccTS.CustCnt.Add(newCustRow);
    BufferCopy.Copy(ccTS.CustCnt[0], ref newCustRow);

    ccTS.CustCnt[0].AttrCodeList = newAttrib + "~" + ccTS.CustCnt[0].AttrCodeList;
    ccTS.CustCnt[0].RowMod = "U";
    
    ccBO.Update(ref ccTS);
  }
}
2 Likes

I could kiss you!

I understand it needs a buffercopy now…

1 Like