Dear Experts,
I have been trying to loop the won opportunities created in current year associated with an account to get the sum of their expected value.
For this I have wrote below code:-
import ABSL; import AP.FO.BusinessPartner.Global; import AP.FO.BusinessPartnerRelationship.Global; import AP.CRM.Global; import AP.FO.Activity.Global; var TotalAmount=0; //var NetCurrency =""; var OppQuery=Opportunity.QueryByElements; var OppParams = OppQuery.CreateSelectionParams(); OppParams.Add(OppQuery.Status.LifeCycleStatusCode,"I", "EQ","2"); OppParams.Add(OppQuery.SalesForecastExpectedProcessingDatePeriod.EndDate,"I","GE",Context.GetCurrentSystemDate().StartOfYear()); OppParams.Add(OppQuery.SalesForecastExpectedProcessingDatePeriod.EndDate,"I","LE",Context.GetCurrentSystemDate().EndOfYear()); //OppParams.Add(OppQuery. var OppRes= OppQuery.Execute(OppParams); if(OppRes.Count()>0) { foreach(var OppIns in OppRes) { if(OppIns.Party.GetFirst().PartyKey.PartyID.content==this.GetFirst().InternalID) { var ExpectedVal= OppIns.SalesForecast.ExpectedRevenueAmount.content; TotalAmount=TotalAmount+ExpectedVal; } this.CurrentCommon.GetFirst().Total=TotalAmount.ToString(); } }
But the final result in field is zero always. Below screenshot
Request you to please help.
Regards,
Pragati
Hi,
Check if the following works (fixed values):
import ABSL;
import AP.CRM.Global;
var query = Opportunity.QueryByElements; var selectionParams = query.CreateSelectionParams();
selectionParams.Add(query.Status.LifeCycleStatusCode, "I", "EQ", "4"); // Won
selectionParams.Add(query.SalesForecastExpectedProcessingDatePeriod.StartDate, "I", "GT", "2016-01-01");
selectionParams.Add(query.SalesForecastExpectedProcessingDatePeriod.EndDate, "I", "LT", "2017-07-01");
var resultData = query.ExecuteDataOnly(selectionParams);
Are you able to query using repository explorer? If so, you can generate the code.
In addition, there are fields such as "partyKey" and "partyRole" in the query. Possibly, your if statement to check the customer is not needed.
Best regards,
Alexandre.
Dear Alexandre,
There are fields such as party key and I used them earlier in my code. But it shows the wrong value in field.
var OppQuery=Opportunity.QueryByElements; var OppParams = OppQuery.CreateSelectionParams(); OppParams.Add(OppQuery.Status.LifeCycleStatusCode,"I", "EQ","4"); OppParams.Add(OppQuery.SalesForecastExpectedProcessingDatePeriod.EndDate,"I","GE",Context.GetCurrentSystemDate().StartOfYear()); OppParams.Add(OppQuery.SalesForecastExpectedProcessingDatePeriod.EndDate,"I","LE",Context.GetCurrentSystemDate().EndOfYear()); OppParams.Add(OppQuery.PartyPartyKey.PartyID.content,"I","EQ", this.GetFirst().InternalID); var OppRes= OppQuery.Execute(OppParams); if(OppRes.Count()>0) { foreach(var OppIns in OppRes) { var ExpectedVal= OppIns.SalesForecast.ExpectedRevenueAmount.content; TotalAmount=TotalAmount+ExpectedVal; } this.CurrentCommon.GetFirst().Total=TotalAmount.ToString(); } <br>
Tried debugging this code found out that internal ID value is equal to the party ID
Also it shows 0 when I put the "if" condition in loop. Can you please check if I am using the correct logic and using the correct fields?
sunil1101 & horst.schaude Can you people please help me here as this has been pending since past 15 days and we are not able to find out the solution.
Regards,
Pragati