Acumatica - Where is the method that writes to CRRelation? - acumatica

Can anyone help me find where in the code Acumatica writes to the CRRelation table when createing a Sales Order from an Opportunity? I've done a search for all instances of "CRRelation" but none of them seem to be doing the actual writing to the table.

It is done in the DoCreateSalesOrder(CreateSalesOrderFilter param) method which is called in the CreateSalesOrder action:
public PXAction<CROpportunity> createSalesOrder;
[PXUIField(DisplayName = Messages.CreateSalesOrder, MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Select)]
[PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntry)]
public virtual IEnumerable CreateSalesOrder(PXAdapter adapter)
{
foreach (CROpportunity opportunity in adapter.Get())
{
Customer customer = (Customer)PXSelect<Customer, Where<Customer.bAccountID, Equal<Current<CROpportunity.bAccountID>>>>
.SelectSingleBound(this, new object[] { opportunity });
if (customer == null)
{
throw new PXException(Messages.ProspectNotCustomer);
}
var products = Products.View.SelectMultiBound(new object[] { opportunity }).RowCast<CROpportunityProducts>();
if (products.Any(_ => _.InventoryID == null) && !products.Any(_ => _.InventoryID != null))
{
throw new PXException(Messages.SalesOrderHasOnlyNonInventoryLines);
}
if (CreateOrderParams.AskExtFullyValid((graph, viewName) => { }, DialogAnswerType.Positive))
{
Save.Press();
PXLongOperation.StartOperation(this, delegate()
{
var grapph = PXGraph.CreateInstance<OpportunityMaint>();
grapph.Opportunity.Current = opportunity;
grapph.CreateOrderParams.Current = CreateOrderParams.Current;
grapph.DoCreateSalesOrder(CreateOrderParams.Current);
});
}
yield return opportunity;
}
}
if we look in that method we can find the following lines which are creating the relation:
var campaignRelation = docgraph.RelationsLink.Insert();
campaignRelation.RefNoteID = doc.NoteID;
campaignRelation.Role = CRRoleTypeList.Source;
campaignRelation.TargetType = CRTargetEntityType.CROpportunity;
campaignRelation.TargetNoteID = opportunity.NoteID;
campaignRelation.DocNoteID = opportunity.NoteID;
campaignRelation.EntityID = opportunity.BAccountID;
campaignRelation.ContactID = opportunity.ContactID;
docgraph.RelationsLink.Update(campaignRelation);
You can find the full code of that method below:
protected virtual void DoCreateSalesOrder(CreateSalesOrderFilter param)
{
bool recalcAny = param.RecalculatePrices == true ||
param.RecalculateDiscounts == true ||
param.OverrideManualDiscounts == true ||
param.OverrideManualDocGroupDiscounts == true ||
param.OverrideManualPrices == true;
var opportunity = this.Opportunity.Current;
Customer customer = (Customer)PXSelect<Customer, Where<Customer.bAccountID, Equal<Current<CROpportunity.bAccountID>>>>.Select(this);
SOOrderEntry docgraph = PXGraph.CreateInstance<SOOrderEntry>();
CurrencyInfo info = PXSelect<CurrencyInfo, Where<CurrencyInfo.curyInfoID, Equal<Current<CROpportunity.curyInfoID>>>>.Select(this);
info.CuryInfoID = null;
info = CurrencyInfo.GetEX(docgraph.currencyinfo.Insert(info.GetCM()));
SOOrder doc = new SOOrder();
doc.OrderType = CreateOrderParams.Current.OrderType ?? SOOrderTypeConstants.SalesOrder;
doc = docgraph.Document.Insert(doc);
doc = PXCache<SOOrder>.CreateCopy(docgraph.Document.Search<SOOrder.orderNbr>(doc.OrderNbr));
doc.CuryInfoID = info.CuryInfoID;
doc = PXCache<SOOrder>.CreateCopy(docgraph.Document.Update(doc));
doc.CuryID = info.CuryID;
doc.OrderDate = Accessinfo.BusinessDate;
doc.OrderDesc = opportunity.Subject;
doc.TermsID = customer.TermsID;
doc.CustomerID = opportunity.BAccountID;
doc.CustomerLocationID = opportunity.LocationID ?? customer.DefLocationID;
if (opportunity.TaxZoneID != null)
{
doc.TaxZoneID = opportunity.TaxZoneID;
if (!recalcAny)
{
SOTaxAttribute.SetTaxCalc<SOLine.taxCategoryID>(docgraph.Transactions.Cache, null, TaxCalc.ManualCalc);
SOTaxAttribute.SetTaxCalc<SOOrder.freightTaxCategoryID>(docgraph.Document.Cache, null,
TaxCalc.ManualCalc);
}
}
doc.ProjectID = opportunity.ProjectID;
doc.BranchID = opportunity.BranchID;
doc = docgraph.Document.Update(doc);
var campaignRelation = docgraph.RelationsLink.Insert();
campaignRelation.RefNoteID = doc.NoteID;
campaignRelation.Role = CRRoleTypeList.Source;
campaignRelation.TargetType = CRTargetEntityType.CROpportunity;
campaignRelation.TargetNoteID = opportunity.NoteID;
campaignRelation.DocNoteID = opportunity.NoteID;
campaignRelation.EntityID = opportunity.BAccountID;
campaignRelation.ContactID = opportunity.ContactID;
docgraph.RelationsLink.Update(campaignRelation);
bool failed = false;
foreach (CROpportunityProducts product in SelectProducts(opportunity.QuoteNoteID))
{
if (product.SiteID == null)
{
InventoryItem item = (InventoryItem)PXSelectorAttribute.Select<CROpportunityProducts.inventoryID>(Products.Cache, product);
if (item != null && item.NonStockShip == true)
{
Products.Cache.RaiseExceptionHandling<CROpportunityProducts.siteID>(product, null,
new PXSetPropertyException(ErrorMessages.FieldIsEmpty, typeof(CROpportunityProducts.siteID).Name));
failed = true;
}
}
SOLine tran = new SOLine();
tran = docgraph.Transactions.Insert(tran);
if (tran != null)
{
tran.InventoryID = product.InventoryID;
tran.SubItemID = product.SubItemID;
tran.TranDesc = product.Descr;
tran.OrderQty = product.Quantity;
tran.UOM = product.UOM;
tran.CuryUnitPrice = product.CuryUnitPrice;
tran.TaxCategoryID = product.TaxCategoryID;
tran.SiteID = product.SiteID;
tran.IsFree = product.IsFree;
tran.ProjectID = product.ProjectID;
tran.TaskID = product.TaskID;
tran.CostCodeID = product.CostCodeID;
tran.ManualPrice = true;
tran.ManualDisc = true;
tran.CuryDiscAmt = product.CuryDiscAmt;
tran.DiscAmt = product.DiscAmt;
tran.DiscPct = product.DiscPct;
tran.POCreate = product.POCreate;
tran.VendorID = product.VendorID;
if (param.RecalculatePrices != true)
{
tran.ManualPrice = true;
}
else
{
if (param.OverrideManualPrices != true)
tran.ManualPrice = product.ManualPrice;
else
tran.ManualPrice = false;
}
if (param.RecalculateDiscounts != true)
{
tran.ManualDisc = true;
}
else
{
if (param.OverrideManualDiscounts != true)
tran.ManualDisc = product.ManualDisc;
else
tran.ManualDisc = false;
}
tran.CuryDiscAmt = product.CuryDiscAmt;
tran.DiscAmt = product.DiscAmt;
tran.DiscPct = product.DiscPct;
}
tran = docgraph.Transactions.Update(tran);
PXNoteAttribute.CopyNoteAndFiles(Products.Cache, product, docgraph.Transactions.Cache, tran,
Setup.Current);
}
PXNoteAttribute.CopyNoteAndFiles(Opportunity.Cache, opportunity, docgraph.Document.Cache, doc, Setup.Current);
if (failed)
throw new PXException(Messages.SiteNotDefined);
//Skip all customer dicounts
if (param.RecalculateDiscounts != true && param.OverrideManualDiscounts != true)
{
var discounts = new Dictionary<string, SOOrderDiscountDetail>();
foreach (SOOrderDiscountDetail discountDetail in docgraph.DiscountDetails.Select())
{
docgraph.DiscountDetails.SetValueExt<SOOrderDiscountDetail.skipDiscount>(discountDetail, true);
string key = discountDetail.Type + ':' + discountDetail.DiscountID + ':' + discountDetail.DiscountSequenceID;
discounts.Add(key, discountDetail);
}
Discount ext = this.GetExtension<Discount>();
foreach (CROpportunityDiscountDetail discountDetail in ext.DiscountDetails.Select())
{
SOOrderDiscountDetail detail;
string key = discountDetail.Type + ':' + discountDetail.DiscountID + ':' + discountDetail.DiscountSequenceID;
if (discounts.TryGetValue(key, out detail))
{
docgraph.DiscountDetails.SetValueExt<SOOrderDiscountDetail.skipDiscount>(detail, false);
if (discountDetail.IsManual == true && discountDetail.Type == DiscountType.Document)
{
docgraph.DiscountDetails.SetValueExt<SOOrderDiscountDetail.extDiscCode>(detail, discountDetail.ExtDiscCode);
docgraph.DiscountDetails.SetValueExt<SOOrderDiscountDetail.description>(detail, discountDetail.Description);
docgraph.DiscountDetails.SetValueExt<SOOrderDiscountDetail.isManual>(detail, discountDetail.IsManual);
docgraph.DiscountDetails.SetValueExt<SOOrderDiscountDetail.curyDiscountAmt>(detail, discountDetail.CuryDiscountAmt);
}
}
else
{
detail = (SOOrderDiscountDetail)docgraph.DiscountDetails.Cache.CreateInstance();
detail.Type = discountDetail.Type;
detail.DiscountID = discountDetail.DiscountID;
detail.DiscountSequenceID = discountDetail.DiscountSequenceID;
detail.ExtDiscCode = discountDetail.ExtDiscCode;
detail.Description = discountDetail.Description;
detail = (SOOrderDiscountDetail)docgraph.DiscountDetails.Cache.Insert(detail);
if (discountDetail.IsManual == true && (discountDetail.Type == DiscountType.Document || discountDetail.Type == DiscountType.ExternalDocument))
{
detail.CuryDiscountAmt = discountDetail.CuryDiscountAmt;
detail.IsManual = discountDetail.IsManual;
docgraph.DiscountDetails.Cache.Update(detail);
}
}
}
SOOrder old_row = PXCache<SOOrder>.CreateCopy(docgraph.Document.Current);
docgraph.Document.Cache.SetValueExt<SOOrder.curyDiscTot>(docgraph.Document.Current, DiscountEngineProvider.GetEngineFor<SOLine, SOOrderDiscountDetail>().GetTotalGroupAndDocumentDiscount(docgraph.DiscountDetails));
docgraph.Document.Cache.RaiseRowUpdated(docgraph.Document.Current, old_row);
}
doc = docgraph.Document.Update(doc);
if (opportunity.TaxZoneID != null && !recalcAny)
{
foreach (CRTaxTran tax in PXSelect<CRTaxTran, Where<CRTaxTran.quoteID, Equal<Current<CROpportunity.quoteNoteID>>>>.Select(this))
{
SOTaxTran newtax = new SOTaxTran();
newtax.LineNbr = int.MaxValue;
newtax.TaxID = tax.TaxID;
newtax = docgraph.Taxes.Insert(newtax);
if (newtax != null)
{
newtax = PXCache<SOTaxTran>.CreateCopy(newtax);
newtax.TaxRate = tax.TaxRate;
newtax.CuryTaxableAmt = tax.CuryTaxableAmt;
newtax.CuryTaxAmt = tax.CuryTaxAmt;
newtax.CuryUnshippedTaxableAmt = tax.CuryTaxableAmt;
newtax.CuryUnshippedTaxAmt = tax.CuryTaxAmt;
newtax.CuryUnbilledTaxableAmt = tax.CuryTaxableAmt;
newtax.CuryUnbilledTaxAmt = tax.CuryTaxAmt;
newtax = docgraph.Taxes.Update(newtax);
}
}
}
if (opportunity.AllowOverrideContactAddress == true)
{
CRContact _CRContact = Opportunity_Contact.SelectSingle();
CRAddress _CRAddress = Opportunity_Address.SelectSingle();
// Insert
if (_CRContact != null)
{
SOBillingContact _billingContact = docgraph.Billing_Contact.Select();
if (_billingContact != null)
{
_billingContact.FullName = _CRContact.FullName;
_billingContact.Salutation = _CRContact.Salutation;
_billingContact.Phone1 = _CRContact.Phone1;
_billingContact.Email = _CRContact.Email;
_billingContact = docgraph.Billing_Contact.Update(_billingContact);
_billingContact.IsDefaultContact = false;
_billingContact = docgraph.Billing_Contact.Update(_billingContact);
}
}
if (_CRAddress != null)
{
SOBillingAddress _billingAddress = docgraph.Billing_Address.Select();
if (_billingAddress != null)
{
_billingAddress.AddressLine1 = _CRAddress.AddressLine1;
_billingAddress.AddressLine2 = _CRAddress.AddressLine2;
_billingAddress.City = _CRAddress.City;
_billingAddress.CountryID = _CRAddress.CountryID;
_billingAddress.State = _CRAddress.State;
_billingAddress.PostalCode = _CRAddress.PostalCode;
_billingAddress = docgraph.Billing_Address.Update(_billingAddress);
_billingAddress.IsDefaultAddress = false;
_billingAddress = docgraph.Billing_Address.Update(_billingAddress);
}
}
}
if (recalcAny)
{
docgraph.recalcdiscountsfilter.Current.OverrideManualPrices = param.OverrideManualPrices == true;
docgraph.recalcdiscountsfilter.Current.RecalcDiscounts = param.RecalculateDiscounts == true;
docgraph.recalcdiscountsfilter.Current.RecalcUnitPrices = param.RecalculatePrices == true;
docgraph.recalcdiscountsfilter.Current.OverrideManualDiscounts = param.OverrideManualDiscounts == true;
docgraph.recalcdiscountsfilter.Current.OverrideManualDocGroupDiscounts = param.OverrideManualDocGroupDiscounts == true;
docgraph.Actions[nameof(Discount.RecalculateDiscountsAction)].Press();
}
if (!this.IsContractBasedAPI)
throw new PXRedirectRequiredException(docgraph, "");
docgraph.Save.Press();
}
NOTE: you can find most part of the sources by the following path in the Acumatica's server folder App_Data\CodeRepository\PX.Objects,App_Data\CodeRepository\PX.Data,App_Data\CodeRepository\PX.Objects.FS

Related

Add an additional line on the grid

I am looking for help, I hope I can solve this problem.
I've created a new screen and I'm filtering all the Revalue Accounts information.
With this screen, what I want to do is insert and at the same time add an additional new line within the grid.
Here is my new created screen and the button that inserts GLTran
I am attaching an image where I want the line to be added at insert time
Here I share code that I have and it does not work for the additional line.
private void CreateDNGL(Batch batch)
{
var graph = PXGraph.CreateInstance<JournalEntry>();
if (graph.BatchModule.Current == null)
{
Batch cmbatch = new Batch();
cmbatch.BranchID = batch.BranchID;
cmbatch.Module = batch.Module;
cmbatch.Status = "U";
cmbatch.AutoReverse = true;
cmbatch.Released = true;
cmbatch.Hold = false;
cmbatch.CuryDebitTotal = batch.CuryDebitTotal;
cmbatch.CuryCreditTotal = batch.CuryCreditTotal;
cmbatch.FinPeriodID = batch.FinPeriodID;
cmbatch.CuryID = batch.CuryID;
cmbatch.CuryInfoID = batch.CuryInfoID;
cmbatch.DebitTotal = batch.DebitTotal;
cmbatch.CreditTotal = batch.CreditTotal;
cmbatch.Description = "Head new insert";
cmbatch = graph.BatchModule.Insert(cmbatch);
}
foreach (GLTran item in PXSelect<GLTran,
Where<GLTran.module, Equal<Required<GLTran.module>>,
And<GLTran.batchNbr, Equal<Required<GLTran.batchNbr>>>>>.Select(this, batch.Module, batch.BatchNbr))
{
GLTran tran = new GLTran();
tran.SummPost = item.SummPost;
tran.ZeroPost = false;
tran.DebitAmt = item.DebitAmt;
tran.CreditAmt = item.CreditAmt;
tran.CuryDebitAmt = item.CuryDebitAmt;
tran.CuryCreditAmt = item.CuryCreditAmt;
tran.AccountID = item.AccountID;
tran.SubID = item.SubID;
tran.LineNbr = item.LineNbr;
tran.LedgerID = item.LedgerID;
tran.TranType = item.TranType;
tran.TranClass = item.TranClass;
tran.RefNbr = string.Empty;
tran.FinPeriodID = item.FinPeriodID;
tran.TranDesc = "Test detail";
tran.Released = true;
tran.ReferenceID = item.ReferenceID;
tran = graph.GLTranModuleBatNbr.Insert(tran);
Account account = PXSelect<Account, Where<Account.accountID,
Equal<Required<Account.accountID>>>>.Select(graph, item.AccountID);
xLocEquivalAcct equivalAcct = PXSelect<xLocEquivalAcct, Where<xLocEquivalAcct.acctCD,
Equal<Required<xLocEquivalAcct.acctCD>>>>.Select(graph, account.AccountCD);
if (equivalAcct != null)
{
/*here is added for an additional line*/
var glTran = graph.GLTranModuleBatNbr.Insert();
graph.GLTranModuleBatNbr.SetValueExt<GLTran.accountID>(glTran, 343567);
graph.GLTranModuleBatNbr.SetValueExt<GLTran.subID>(glTran, 281);
glTran.TranDesc = "add extra line";
if (item.DebitAmt != 0m && item.CreditAmt == 0m)
{
if (batch.Module == BatchModule.CM)
{
graph.GLTranModuleBatNbr.SetValueExt<GLTran.curyDebitAmt>(glTran, item.CuryDebitAmt);
graph.GLTranModuleBatNbr.SetValueExt<GLTran.debitAmt>(glTran, item.DebitAmt);
}
}
if (item.CreditAmt != 0m && item.DebitAmt == 0m)
{
if (batch.Module == BatchModule.CM)
{
graph.GLTranModuleBatNbr.SetValueExt<GLTran.curyCreditAmt>(glTran, item.CuryCreditAmt);
graph.GLTranModuleBatNbr.SetValueExt<GLTran.creditAmt>(glTran, item.CreditAmt);
}
}
glTran = graph.GLTranModuleBatNbr.Update(glTran);
}
}
graph.Save.Press();
}
I hope I was clear with my question.
This code will create a copy of the originating batch and insert additional lines.
#Warning Your original code was attempting to create a batch that was already released but unposted. I can update my answer to match your requirement but this will break Acumatica work-flow.
Please find code example below :
public class JournalEntryExtension : PXGraphExtension<JournalEntry>
{
public PXAction<Batch> CopyCreate;
//CommitChanges being set to false allows the graph to not be considered dirty when there are errors that we manually show on screen. Case #207998
[PXButton(CommitChanges = false)]
[PXUIField(DisplayName = "Copy Create", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update, Enabled = true)]
protected virtual IEnumerable copyCreate(PXAdapter pxAdapter)
{
if (Base.BatchModule.Current != null)
{
if (Base.IsDirty)
{
Base.BatchModule.Ask("You must discard your unsaved changes to be able to press this button.", MessageButtons.OK);
}
else
{
Batch batch = Base.BatchModule.Current;
PXLongOperation.StartOperation(this, () => CreateDNGL(batch));
}
}
return pxAdapter.Get();
}
private static void CreateDNGL(Batch batch)
{
JournalEntry graph = PXGraph.CreateInstance<JournalEntry>();
Batch newBatch = PXCache<Batch>.CreateCopy(batch);
newBatch.NoteID = null;
newBatch.Description = "Test header";
newBatch = graph.BatchModule.Insert(newBatch);
GLTran newTran;
foreach (GLTran tran in PXSelectReadonly<GLTran,
Where<GLTran.module, Equal<Required<GLTran.module>>,
And<GLTran.batchNbr, Equal<Required<GLTran.batchNbr>>>>>.Select(graph, batch.Module, batch.BatchNbr))
{
newTran = PXCache<GLTran>.CreateCopy(tran);
newTran.Module = null;
newTran.BatchNbr = null;
newTran.NoteID = null;
newTran.TranDesc = "Test detail";
newTran = graph.GLTranModuleBatNbr.Insert(newTran);
}
if (true)
{
newTran = graph.GLTranModuleBatNbr.Insert();
newTran.AccountID = 1190;
newTran.SubID = 467;
newTran.CuryDebitAmt = 1000;
newTran.TranDesc = "Additional Line 1";
newTran = graph.GLTranModuleBatNbr.Update(newTran);
newTran = graph.GLTranModuleBatNbr.Insert();
newTran.AccountID = 1190;
newTran.SubID = 467;
newTran.CuryCreditAmt = 1000;
newTran.TranDesc = "Additional Line 2";
newTran = graph.GLTranModuleBatNbr.Update(newTran);
}
graph.Save.Press();
}
}
Original Batch :
New Batch :

How to update the ext price field in the sales orders screen

I found a small detail on the sales order screen, which when adding two custom fields generates a new price as shown in the image.
but at the moment of generating the new value at the unit price I am surprised that the ext price will not be updated and the other fields which are marked with green.
I am attaching my code and I would like them to tell me what I am failing or what I need to do, so that when updating the unit price the other fields are automatically updated since I am only modifying the unitprice.
besides that I have also used the commit change = true, but it is not working for me.
I thank you for your support,
namespace PX.Objects.SO
{
public class PESKSOOrderEntry6_Extension : PXGraphExtension<SOOrderEntry>
{
#region Event Handlers
public const string PMBudgetType = "I";
//STATE
public const string eNY = "NY";
public const string ePA = "PA";
//UOM
public const string uTN = "TN";
public const string uGL = "GL";
protected virtual void SOLine_CuryUnitPrice_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
sender.SetValuePending<SOLine.curyDiscPrice>(e.Row, PXCache.NotSetValue);
}
protected void _(Events.RowUpdated<SOLine> e)
{
var row = (SOLine)e.Row;
var row1 = (SOLine)e.OldRow;
SOOrder soOrder = Base.Document.Current;
if (row == null) return;
var rowExt = row.GetExtension<SOLineExt>();
var rowExt1 = row1.GetExtension<SOLineExt>();
PMRevenueBudget pmBudget = GetPMRevenueBudget(row.ProjectID, row.TaskID, row.InventoryID, PMBudgetType, row.UOM);
var pmBudgetExt = pmBudget.GetExtension<PMBudgetExt>();
if (row.InventoryID != null && row.OrderQty != 0 && row.TaskID != null && pmBudget != null && (rowExt.UsrSPriceIndex == false || rowExt.UsrSPriceIndex == null))
{
rowExt.UsrSPriceIndex = pmBudgetExt.UsrSPriceIndex;
rowExt.UsrQuoteUnitPrice = pmBudget.Rate;
row.CuryUnitPrice = pmBudget.Rate;
//row.CuryExtPrice = row.OrderQty * row.CuryUnitPrice;
//row.CuryDiscPrice = row.CuryExtPrice;
//row.CuryLineAmt = row.CuryExtPrice;
//row.CuryUnbilledAmt = row.CuryExtPrice;
}
else
{
rowExt.UsrSPriceIndex = false;
}
if (row.InventoryID != null && row.OrderQty != 0 && row.TaskID != null && pmBudget != null && rowExt.UsrSPriceIndex == true)
{
rowExt.UsrQuoteUnitPrice = pmBudget.Rate;
PESKPriceIndexCat pricecat = GetPESKPriceIndexCat(row.InventoryID);
decimal? nempriceIndex = 0, baseIndex = 0, aPercent = 0;
nempriceIndex = NewEfecctiveMPriceIndex(soOrder, pricecat, nempriceIndex);
baseIndex = BaseIndex(pmBudgetExt, baseIndex);
aPercent = AsphaltPercent(row, pricecat, aPercent);
if (pricecat != null && pricecat.State == eNY)
{
if (row.UOM == uTN)
{
//((New Effective Monthly Price Index) – (Base Index)) x Asphalt Percent
rowExt.UsrIndexAdj = (((nempriceIndex) - (baseIndex)) * (aPercent / 100));
row.CuryUnitPrice = rowExt.UsrQuoteUnitPrice + rowExt.UsrIndexAdj;
//row.CuryExtPrice = row.OrderQty * row.CuryUnitPrice;
//row.CuryDiscPrice = row.CuryExtPrice;
//row.CuryLineAmt = row.CuryExtPrice;
//row.CuryUnbilledAmt = row.CuryExtPrice;
}
if (row.UOM == uGL)
{
//(((New Effective Monthly Index Price) – (Base Index))/ 235) x Asphalt Percent
decimal? num = 235;
rowExt.UsrIndexAdj = ((((nempriceIndex) - (baseIndex)) / num) * (aPercent / 100));
row.CuryUnitPrice = rowExt.UsrQuoteUnitPrice + rowExt.UsrIndexAdj;
//row.CuryExtPrice = row.OrderQty * row.CuryUnitPrice;
//row.CuryDiscPrice = row.CuryExtPrice;
//row.CuryLineAmt = row.CuryExtPrice;
//row.CuryUnbilledAmt = row.CuryExtPrice;
}
}
if (pricecat != null && pricecat.State == ePA)
{
if (row.UOM == uTN)
{
var resul = (((nempriceIndex) - (baseIndex)) * (aPercent / 100));
var diff = resul - baseIndex;
decimal? diff1 = baseIndex * Convert.ToDecimal(0.1);
if (diff == diff1)
{
//((New Effective Monthly Price Index) – (Base Index)) x Asphalt Percent
rowExt.UsrIndexAdj = resul;
row.CuryUnitPrice = rowExt.UsrQuoteUnitPrice + rowExt.UsrIndexAdj;
//row.CuryExtPrice = row.OrderQty * row.CuryUnitPrice;
//row.CuryDiscPrice = row.CuryExtPrice;
//row.CuryLineAmt = row.CuryExtPrice;
//row.CuryUnbilledAmt = row.CuryExtPrice;
}
}
if (row.UOM == uGL)
{
decimal? num = 235;
var resul = ((((nempriceIndex) - (baseIndex)) / num) * (aPercent / 100));
var diff = resul - baseIndex;
decimal? diff1 = baseIndex * Convert.ToDecimal(0.1);
if (diff == diff1)
{
//(((New Effective Monthly Index Price) – (Base Index))/ 235) x Asphalt Percent
rowExt.UsrIndexAdj = resul;
row.CuryUnitPrice = rowExt.UsrQuoteUnitPrice + rowExt.UsrIndexAdj;
//row.CuryExtPrice = row.OrderQty * row.CuryUnitPrice;
//row.CuryDiscPrice = row.CuryExtPrice;
//row.CuryLineAmt = row.CuryExtPrice;
//row.CuryUnbilledAmt = row.CuryExtPrice;
}
}
}
}
}
//how to calculate field Index Adj
protected void _(Events.RowSelected<SOLine> e)
{
var row = (SOLine)e.Row;
SOOrder soOrder = Base.Document.Current;
if (row == null) return;
var rowExt = row.GetExtension<SOLineExt>();
#region Enabled and Disable
PMRevenueBudget pmBudget = GetPMRevenueBudget(row.ProjectID, row.TaskID, row.InventoryID, PMBudgetType, row.UOM);
if (row.InventoryID != null && row.OrderQty != 0 && row.TaskID != null && pmBudget != null)
{
PXUIFieldAttribute.SetEnabled<SOLineExt.usrQuoteUnitPrice>(e.Cache, e.Row, true);
PXUIFieldAttribute.SetEnabled<SOLineExt.usrIndexAdj>(e.Cache, e.Row, true);
rowExt.UsrQuoteUnitPrice = 0;
rowExt.UsrIndexAdj = 0;
}
else
{
PXUIFieldAttribute.SetEnabled<SOLineExt.usrQuoteUnitPrice>(e.Cache, e.Row, false);
PXUIFieldAttribute.SetEnabled<SOLineExt.usrIndexAdj>(e.Cache, e.Row, false);
}
if (rowExt.UsrSPriceIndex == true)
{
PXUIFieldAttribute.SetEnabled<SOLineExt.usrIndexAdj>(e.Cache, e.Row, true);
}
else
{
PXUIFieldAttribute.SetEnabled<SOLineExt.usrIndexAdj>(e.Cache, e.Row, false);
rowExt.UsrQuoteUnitPrice = 0;
rowExt.UsrIndexAdj = 0;
}
#endregion
}
#region Method
private decimal? AsphaltPercent(SOLine row, PESKPriceIndexCat pricecat, decimal? aPercent)
{
foreach (PESKStockItem res3 in PXSelect<PESKStockItem,
Where<PESKStockItem.inventoryID, Equal<Required<PESKStockItem.inventoryID>>,
And<PESKStockItem.categoryID, Equal<Required<PESKStockItem.categoryID>>>
>>.Select(Base, row.InventoryID, pricecat.CategoryCD))
{
if (res3 != null)
{
//Asphalt Percent
aPercent = res3.AsphaltPct;
}
}
return aPercent;
}
private decimal? BaseIndex(PMBudgetExt contraExt, decimal? baseIndex)
{
PESKPriceIndexDetail res2 = PXSelectJoin<PESKPriceIndexDetail,
InnerJoin<PESKPRC,
On<PESKPRC.priceIndexID, Equal<PESKPriceIndexDetail.priceIndexID>>>,
Where<PESKPRC.recordID, Equal<Required<PESKPRC.recordID>>>>
.Select(Base, contraExt.UsrPRCNumber);
if (res2 != null)
{
//Base Index
baseIndex = res2.BaseIndex;
}
return baseIndex;
}
private decimal? NewEfecctiveMPriceIndex(SOOrder soOrder, PESKPriceIndexCat pricecat, decimal? nempriceIndex)
{
Dictionary<int?, object> Mydict1 = new Dictionary<int?, object>();
Dictionary<int?, object> Mydict2 = new Dictionary<int?, object>();
foreach (PESKPriceIndexDetail res in PXSelect<PESKPriceIndexDetail,
Where<PESKPriceIndexDetail.categoryID, Equal<Required<PESKPriceIndexDetail.categoryID>>>>
.Select(Base, pricecat.CategoryID))
{
if (res != null)
{
if (res.EffDate <= soOrder.OrderDate)
{
if (!Mydict1.ContainsKey(res.PriceIndexID))
{
Mydict1.Add(res.PriceIndexID, res.EffDate);
}
}
}
}
var maxfecha = (from mydic in Mydict1 select mydic.Value).Max();
nempriceIndex = 0;
PESKPriceIndexDetail res1 = PXSelect<PESKPriceIndexDetail,
Where<PESKPriceIndexDetail.categoryID, Equal<Required<PESKPriceIndexDetail.categoryID>>,
And<PESKPriceIndexDetail.effDate, Equal<Required<PESKPriceIndexDetail.effDate>>>>>
.Select(Base, pricecat.CategoryID, maxfecha);
if (res1 != null)
{
//New Effective Monthly Price Index
nempriceIndex = res1.BaseIndex;
}
return nempriceIndex;
}
#endregion
#endregion
#region Metodos Realizados
public static PXGraph GetGraph(PXGraph graph = null)
{
if (graph == null)
{
graph = new PXGraph();
}
return graph;
}
public static List<TDac> PXResultSetToList<TDac>(PXResultset<TDac> resultSet) where TDac : class, IBqlTable, new()
{
List<TDac> list = new List<TDac>();
foreach (PXResult<TDac> item2 in resultSet)
{
TDac item = item2;
list.Add(item);
}
return list;
}
public static PMRevenueBudget GetPMRevenueBudget(int? ProjectID, int? TaskID, int? InventoryID, string PMBudgetType, string UOM, PXGraph graph = null)
{
graph = GetGraph(graph);
PXResultset<PMRevenueBudget> l = PXSelectBase<
PMRevenueBudget, PXSelect<
PMRevenueBudget,
Where<PMRevenueBudget.projectID, Equal<Required<PMRevenueBudget.projectID>>,
And<PMRevenueBudget.projectTaskID, Equal<Required<PMRevenueBudget.projectTaskID>>,
And<PMRevenueBudget.inventoryID, Equal<Required<PMRevenueBudget.inventoryID>>,
And<PMRevenueBudget.type, Equal<Required<PMRevenueBudget.type>>,
And<PMRevenueBudget.uOM, Equal<Required<PMRevenueBudget.uOM>>>>
>>>>.Config>
.Select(graph, ProjectID, TaskID, InventoryID, PMBudgetType, UOM);
return l;
}
public static PESKPriceIndexCat GetPESKPriceIndexCat(int? InventoryID, PXGraph graph = null)
{
graph = GetGraph(graph);
return PXSelectBase<
PESKPriceIndexCat, PXSelectJoin<
PESKPriceIndexCat,
InnerJoin<PESKStockItem,
On<PESKStockItem.categoryID,
Equal<PESKPriceIndexCat.categoryCD>>>,
Where<PESKStockItem.inventoryID,
Equal<Required<PESKStockItem.inventoryID>>>>.Config>
.Select(graph, InventoryID);
}
#endregion
}
}
By using graph.View.SetValueExt<>(), you can take advantage of field events, which is what updates those fields automatically.
It will take a bit of re-coding, but it would look something like this: (notice the first line and last two lines)
protected void _(Events.RowUpdated<SOLine> e)
{
var orderGraph = (SOOrderEntry)e.Cache.Graph; // ***NEW***
var row = (SOLine)e.Row;
var row1 = (SOLine)e.OldRow;
SOOrder soOrder = Base.Document.Current;
if (row == null) return;
var rowExt = row.GetExtension<SOLineExt>();
var rowExt1 = row1.GetExtension<SOLineExt>();
PMRevenueBudget pmBudget = GetPMRevenueBudget(row.ProjectID, row.TaskID, row.InventoryID, PMBudgetType, row.UOM);
var pmBudgetExt = pmBudget.GetExtension<PMBudgetExt>();
if (row.InventoryID != null && row.OrderQty != 0 && row.TaskID != null && pmBudget != null && (rowExt.UsrSPriceIndex == false || rowExt.UsrSPriceIndex == null))
{
rowExt.UsrSPriceIndex = pmBudgetExt.UsrSPriceIndex;
rowExt.UsrQuoteUnitPrice = pmBudget.Rate;
orderGraph.Transactions.SetValueExt<SOLine.curyUnitPrice>(row, pmBudget.Rate); // ***NEW***
//row.CuryUnitPrice = pmBudget.Rate; ***OLD***
//.... other code
}
}
I think this may resolve your issue.

how to fill grid view with dataset

i have done code to fill up grid view with data set.
just look at :
public void FillGrid(string StartAlpha, string CommandName, string ColumnName, string SearchText)
{
using (DataClassesDataContext db = new DataClassesDataContext())
{
int userid = db.Users.Where(u => u.EmailAddress.Equals((String)Session["EmailID"])).Select(u => u.Id).SingleOrDefault();
var sms = Enumerable.Repeat(new
{
Id = default(int),
Title = string.Empty,
Body = string.Empty,
FromUser = string.Empty,
ToUser = string.Empty,
SentDateTime = default(DateTime?),
IsMedia = default(bool),
CreatedDate = default(DateTime),
}, 1).ToList();
DataSet myDataSet = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Id", typeof(string)));
dt.Columns.Add(new DataColumn("Title", typeof(string)));
dt.Columns.Add(new DataColumn("Body", typeof(string)));
dt.Columns.Add(new DataColumn("FromUser", typeof(string)));
dt.Columns.Add(new DataColumn("ToUser", typeof(string)));
dt.Columns.Add(new DataColumn("SentDateTime", typeof(DateTime)));
dt.Columns.Add(new DataColumn("IsMedia", typeof(bool)));
dt.Columns.Add(new DataColumn("CreatedDate", typeof(DateTime)));
if (StartAlpha.Equals("All"))
{
switch (CommandName)
{
case "Inbox":
break;
case "Outbox":
lbl_countall.Text = db.SMS.Where(s => s.SentDateTime != null).Count().ToString();
lbut_showinbox.Font.Bold = false;
lbut_showoutbox.Font.Bold = true;
lbut_showdraffs.Font.Bold = false;
sms = db.SMS.OrderByDescending(s => s.SentDateTime).Where(s => (s.SentDateTime != null || s.IsDraft.Equals(false)) & s.user_id.Equals(userid)).Select(s => new
{
Id = s.Id,
Title = s.Title,
Body = s.Body,
FromUser = db.SMSAccounts.Where(a=>a.user_id.Equals(userid)).Select(a=>a.FromMobileNo).FirstOrDefault(),
ToUser = s.To_MobileNo,
SentDateTime = s.SentDateTime,
IsMedia = false,
CreatedDate = s.CreatedDate
}).FilterForColumn(ColumnName, SearchText).ToList();
foreach (var item in sms)
{
if (item != null)
{
DataRow dr = dt.NewRow();
dr["Id"] = item.Id.ToString();
dr["Title"] = item.Title.ToString();
dr["Body"] = Regex.Replace(item.Body.ToString().Trim(), #"<(.|\n)*?>", string.Empty);
dr["FromUser"] = item.FromUser.ToString();
if (item.ToUser != null)
{
dr["ToUser"] = item.ToUser.ToString();
}
else
{
dr["ToUser"] = "NoN";
}
if (item.SentDateTime != null)
{
dr["SentDatetTime"] = item.SentDateTime;
}
else
{
dr["SentDatetTime"] = DBNull.Value;
}
dr["IsMedia"] = item.IsMedia;
dr["CreatedDate"] = item.CreatedDate;
dt.Rows.Add(dr);
}
}
break;
case "Drafts":
lbl_countall.Text = db.SMS.Where(s => s.SentDateTime != null || s.IsDraft.Equals(true)).Count().ToString();
lbut_showinbox.Font.Bold = false;
lbut_showoutbox.Font.Bold = false;
lbut_showdraffs.Font.Bold = true;
sms = db.SMS.OrderByDescending(s => s.SentDateTime).Where(s => (s.SentDateTime == null || s.IsDraft.Equals(true)) & s.user_id.Equals(userid)).Select(s => new
{
Id = s.Id,
Title = s.Title,
Body = s.Body,
FromUser = db.SMSAccounts.Where(a => a.user_id.Equals(userid)).Select(a => a.FromMobileNo).FirstOrDefault(),
ToUser = s.To_MobileNo,
SentDateTime = s.SentDateTime,
IsMedia = false,
CreatedDate = s.CreatedDate
}).FilterForColumn(ColumnName, SearchText).ToList();
foreach (var item in sms)
{
if (item != null)
{
DataRow dr = dt.NewRow();
dr["Id"] = item.Id.ToString();
dr["Title"] = item.Title.ToString();
dr["Body"] = Regex.Replace(item.Body.ToString().Trim(), #"<(.|\n)*?>", string.Empty);
dr["FromUser"] = item.FromUser.ToString();
if (item.ToUser != null)
{
dr["ToUser"] = item.ToUser.ToString();
}
else
{
dr["ToUser"] = "NoN";
}
if (item.SentDateTime != null)
{
dr["SentDatetTime"] = item.SentDateTime;
}
else
{
dr["SentDatetTime"] = DBNull.Value;
}
dr["IsMedia"] = item.IsMedia;
dr["CreatedDate"] = item.CreatedDate;
dt.Rows.Add(dr);
}
}
break;
}
}
else
{
switch (CommandName)
{
//case "Inbox":
.............
// break;
case "Outbox":
lbl_countall.Text = db.SMS.Where(s => s.SentDateTime != null).Count().ToString();
lbut_showinbox.Font.Bold = false;
lbut_showoutbox.Font.Bold = true;
lbut_showdraffs.Font.Bold = false;
sms = db.SMS.OrderByDescending(s => s.SentDateTime).Where(s => (s.SentDateTime != null || s.IsDraft.Equals(false)) & s.user_id.Equals(userid)).Select(s => new
{
Id = s.Id,
Title = s.Title,
Body = s.Body,
FromUser = db.SMSAccounts.Where(a => a.user_id.Equals(userid)).Select(a => a.FromMobileNo).FirstOrDefault(),
ToUser = s.To_MobileNo,
SentDateTime = s.SentDateTime,
IsMedia = false,
CreatedDate = s.CreatedDate
}).FilterForColumn(ColumnName, SearchText).ToList().Where(x => x.Title.StartsWith(StartAlpha, StringComparison.CurrentCultureIgnoreCase)).ToList();
foreach (var item in sms)
{
if (item != null)
{
DataRow dr = dt.NewRow();
dr["Id"] = item.Id.ToString();
dr["Title"] = item.Title.ToString();
dr["Body"] = Regex.Replace(item.Body.ToString().Trim(), #"<(.|\n)*?>", string.Empty);
dr["FromUser"] = item.FromUser.ToString();
if (item.ToUser != null)
{
dr["ToUser"] = item.ToUser.ToString();
}
else
{
dr["ToUser"] = "NoN";
}
if (item.SentDateTime != null)
{
dr["SentDatetTime"] = item.SentDateTime;
}
else
{
dr["SentDatetTime"] = DBNull.Value;
}
dr["IsMedia"] = item.IsMedia;
dr["CreatedDate"] = item.CreatedDate;
dt.Rows.Add(dr);
}
}
break;
case "Drafts":
lbl_countall.Text = db.SMS.Where(s => s.SentDateTime != null).Count().ToString();
lbut_showinbox.Font.Bold = false;
lbut_showoutbox.Font.Bold = false;
lbut_showdraffs.Font.Bold = true;
sms = db.SMS.OrderByDescending(s => s.SentDateTime).Where(s => (s.SentDateTime == null || s.IsDraft.Equals(true)) & s.user_id.Equals(userid)).Select(s => new
{
Id = s.Id,
Title = s.Title,
Body = s.Body,
FromUser = db.SMSAccounts.Where(a => a.user_id.Equals(userid)).Select(a => a.FromMobileNo).FirstOrDefault(),
ToUser = s.To_MobileNo,
SentDateTime = s.SentDateTime,
IsMedia = false,
CreatedDate = s.CreatedDate
}).FilterForColumn(ColumnName, SearchText).ToList().Where(x => x.Title.StartsWith(StartAlpha, StringComparison.CurrentCultureIgnoreCase)).ToList();
foreach (var item in sms)
{
if (item != null)
{
DataRow dr = dt.NewRow();
dr["Id"] = item.Id.ToString();
dr["Title"] = item.Title.ToString();
dr["Body"] = Regex.Replace(item.Body.ToString().Trim(), #"<(.|\n)*?>", string.Empty);
dr["FromUser"] = item.FromUser.ToString();
if (item.ToUser != null)
{
dr["ToUser"] = item.ToUser.ToString();
}
else
{
dr["ToUser"] = "NoN";
}
if (item.SentDateTime != null)
{
dr["SentDatetTime"] = item.SentDateTime;
}
else
{
dr["SentDatetTime"] = DBNull.Value;
}
dr["IsMedia"] = item.IsMedia;
dr["CreatedDate"] = item.CreatedDate;
dt.Rows.Add(dr);
}
}
break;
}
}
myDataSet.Tables.Add(dt);
if (myDataSet.Tables[0].Rows.Count > 0)
{
DataView myDataView = new DataView();
myDataView = myDataSet.Tables[0].DefaultView;
if (this.ViewState["SortExp"] != null)
{
myDataView.Sort = this.ViewState["SortExp"].ToString()
+ " " + this.ViewState["SortOrder"].ToString();
}
GV_ViewSMS.DataSource = myDataView;
}
if (GV_ViewSMS.Rows.Count != 0)
{
SetPageNumbers();
}
GV_ViewSMS.DataBind();
}
}
and this error occurs :
Server Error in '/' Application.
Column 'SentDatetTime' does not belong to table .
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Column 'SentDatetTime' does not belong to table .
Source Error:
Line 439: else
Line 440: {
Line 441: dr["SentDatetTime"] = DBNull.Value;
Line 442: }
Line 443: dr["IsMedia"] = item.IsMedia;
Source File: e:\EASYMAIL_off\EASYMAIL\BulkSMS.aspx.cs Line: 441
Stack Trace:
[ArgumentException: Column 'SentDatetTime' does not belong to table .]
System.Data.DataRow.GetDataColumn(String columnName) +5731291
System.Data.DataRow.set_Item(String columnName, Object value) +13
BulkSMS.FillGrid(String StartAlpha, String CommandName, String ColumnName, String SearchText) in e:\EASYMAIL_off\EASYMAIL\BulkSMS.aspx.cs:441
BulkSMS.Page_Load(Object sender, EventArgs e) in e:\EASYMAIL_off\EASYMAIL\BulkSMS.aspx.cs:40
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +95
System.Web.UI.Control.LoadRecursive() +59
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +678
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0
What wrong with my Code?????
please help me to throughout this problem.....
Looks like you have a spelling error SentDatetTime -> SentDateTime:
if (item.SentDateTime != null)
{
dr["SentDateTime"] = item.SentDateTime;
}
else
{
dr["SentDateTime"] = DBNull.Value;
}

Batch bills- Submission Id

I need to grab the batch bill submission id (from different vendors) of the object from netsuite.Does anyone know how to do this?
TransactionSearchBasic transSearch = new TransactionSearchBasic();
SearchResult resVendorBill = service.search(transSearch);
resVendorBill.pageSize = 25;
resVendorBill.pageSizeSpecified = true;
resVendorBill.totalRecords = SearchRecentTransCount;
resVendorBill.totalRecordsSpecified = true;
transSearch.recordType = new SearchStringField() { #operator = SearchStringFieldOperator.#is, searchValue = "vendorpayment", operatorSpecified = true };
SearchResult resVendorPayment = service.search(transSearch);
if (resVendorPayment.status.isSuccess)
{
Record[] searchPaymentRecords = resVendorPayment.recordList;
if (searchPaymentRecords != null && searchPaymentRecords.Length >= 1)
{
List<VendorPayment> lstVendorPayments = searchPaymentRecords.Select(ep => (VendorPayment)ep).OrderByDescending(epo => epo.createdDate).Take(SearchRecentTransCount).ToList();
}
}

Exchange WebService - Errorcode ErrorIncorrectUpdatePropertyCount when updateing contact

I use the fallowing method to update a contact in Exchange over EWS:
private void UpdateContact(Microsoft.Exchange.WebServices.Data.Contact exContact, ContactInfo contact) {
var pathList = new List<string>();
try {
log.DebugFormat("Process ExchangeContact '{0}' with Contact '{1}'", (exContact.IsNew ? "<new>" : exContact.DisplayName), contact.Id);
exContact.GivenName = contact.AdditionalName;
exContact.Surname = contact.Name;
exContact.FileAsMapping = FileAsMapping.SurnameCommaGivenName;
exContact.CompanyName = "";
if (contact is PersonInfo) {
var person = (PersonInfo) contact;
if (person.PersonCompany != null && person.PersonCompany.Company != null) {
exContact.CompanyName = person.PersonCompany.Company.DisplayName;
}
exContact.ImAddresses[ImAddressKey.ImAddress1] = person.MessengerName;
exContact.ImAddresses[ImAddressKey.ImAddress2] = person.SkypeName;
}
// Specify the business, home, and car phone numbers.
var comm = contact.GetCommunication(Constants.CommunicationType.PhoneBusiness);
exContact.PhoneNumbers[PhoneNumberKey.BusinessPhone] = (comm != null ? comm.Value : null);
comm = contact.GetCommunication(Constants.CommunicationType.PhonePrivate);
exContact.PhoneNumbers[PhoneNumberKey.HomePhone] = (comm != null ? comm.Value : null);
comm = contact.GetCommunication(Constants.CommunicationType.PhoneMobile);
exContact.PhoneNumbers[PhoneNumberKey.MobilePhone] = (comm != null ? comm.Value : null);
comm = contact.GetCommunication(Constants.CommunicationType.MailBusiness);
exContact.EmailAddresses[EmailAddressKey.EmailAddress1] = (comm != null ? new EmailAddress(comm.Value) : null);
comm = contact.GetCommunication(Constants.CommunicationType.MailPrivate);
exContact.EmailAddresses[EmailAddressKey.EmailAddress2] = (comm != null ? new EmailAddress(comm.Value) : null);
// Specify two IM addresses.
// Specify the home address.
var address = contact.AddressList.FirstOrDefault(x => x.AddressType != null && x.AddressType.Id == Constants.AddressType.Private);
if (address != null) {
var paEntry = new PhysicalAddressEntry
{
Street = address.Street,
City = address.City,
State = address.Region,
PostalCode = address.PostalCode,
CountryOrRegion = address.CountryName
};
exContact.PhysicalAddresses[PhysicalAddressKey.Home] = paEntry;
if (contact.PostalAddress == address) {
exContact.PostalAddressIndex = PhysicalAddressIndex.Home;
}
} else {
exContact.PhysicalAddresses[PhysicalAddressKey.Home] = null;
}
address = contact.AddressList.FirstOrDefault(x => x.AddressType != null && x.AddressType.Id == Constants.AddressType.Business);
if (address != null) {
var paEntry = new PhysicalAddressEntry
{
Street = address.Street,
City = address.City,
State = address.Region,
PostalCode = address.PostalCode,
CountryOrRegion = address.CountryName
};
exContact.PhysicalAddresses[PhysicalAddressKey.Business] = paEntry;
if(contact.PostalAddress == address) {
exContact.PostalAddressIndex = PhysicalAddressIndex.Business;
}
} else {
exContact.PhysicalAddresses[PhysicalAddressKey.Business] = null;
}
// Save the contact.
if (exContact.IsNew) {
exContact.Save();
} else {
exContact.Update(ConflictResolutionMode.AlwaysOverwrite);
}
pathList.AddRange(this.AddFileAttachments(this.Access.IndependService.GetContact(exContact.Id.UniqueId), contact.GetDocuments()));
} catch(Exception e) {
log.Error("Error updating/inserting Contact in Exchange.", e);
} finally {
foreach (var path in pathList) {
this.Access.Context.Container.Resolve<IDocumentService>().UndoCheckOut(path);
}
}
}
When I do this for update, I get an Exception with Errorcode ErrorIncorrectUpdatePropertyCount on the line exContact.Update(ConflictResolutionMode.AlwaysOverwrite);
Can someone help me, what is the problem? - Thanks.
The solution is that I have to check, if the string-values are empty strings and in this case to set null. On this way, all is working.

Resources