Community
Showing results for 
Search instead for 
Do you mean 
Reply

recalculate opportunity

Accepted Solution Solved
Copper Contributor
Posts: 29
Country: Germany
Accepted Solution

recalculate opportunity

Hallo,

 

I am looking for a function to push the calculation of the Opportunity fields like GrossMargin.

We can update the opportunites by sdk, but need to get the GrossMargin directly after the update.

But this is not working, still have the old values.

 

How can I get the calculation running via SDK?

 

Thanks in advance Susanne

 


Accepted Solutions
Solution
Accepted by sam_raikes (Copper Super Contributor)
‎09-25-2015 03:20 AM
Copper Super Contributor
Posts: 52
Country: United_Kingdom

Re: recalculate opportunity

[ Edited ]

Hi Susanne,

 

I can see your problem. I created my own opportunity dialog which I load an opportunity into and then add a product. Although it does update the opportunity, my dialog doesn't when I try and reload the properties/values from the Opportunity object.

 

It seems that it updates the database but doesn't update the Opportunity object you're referencing.

 

I've found a solution though. I load the opportunity into the dialog like this:

 

private void LoadOpportunity()
{
    name_tb.Text = o.Name;
    total_tb.Text = o.ProductTotal.ToString();

    string weighted = o.WeightedTotal.ToString();
    weighted = weighted.Substring(0, weighted.LastIndexOf(".") + 3);
    weighted_tb.Text = weighted;

    gross_tb.Text = o.GrossMargin.ToString();

    probability_tb.Text = o.Probability.ToString();

    process_tb.Text = o.Stage.Process.Name;
    stage_tb.Text = o.Stage.Name;

    if (o.Status == OpportunityStatus.Open) { open_rb.Checked = true; }
    else if (o.Status == OpportunityStatus.Won) { won_rb.Checked = true; }
    else if (o.Status == OpportunityStatus.Lost) { lost_rb.Checked = true; }
    else if (o.Status == OpportunityStatus.Inactive) { inactive_rb.Checked = true; }
}

 

I then add products to the opportunity like this:

 

private void AddProductToOpportunity(string productName, decimal cost, decimal price)
{
    OpportunityProduct oppProd = aFwk.Products.OpportunityProductManager.CreateCustomEntity();
    oppProd.Name = productName;
    oppProd.ItemNumber = productName;
    oppProd.Quantity = 1.00m;
    oppProd.Cost = cost;
    oppProd.Price = price;
    oppProd.Discount = 0.00m;
    oppProd.Update();

    o.UpdateProducts(new OpportunityProduct[] { oppProd }, null);
    o.Update();
}

 

Finally, I referesh the dialog like this:

 

private void refreshOpportunity()
{
    //create a guid arry containing just this opportunity
    List<Guid> guids = new List<Guid>();
    guids.Add(o.ID);
    Guid[] idArray = guids.ToArray();

    //set the opportunity to null
    o = null;

    //re-get the opportunity
    OpportunityList ol = aFwk.Opportunities.GetOpportunitiesByID(null, idArray);
    o = ol[0];

    //reload
    LoadOpportunity();
 }

 

The important part being that you null your reference to the opportunity and then obtain it again from the framework.

 

I hope this helps.

 

Kind regards,

 


Russell

View solution in original post


All Replies
Copper Super Contributor
Posts: 52
Country: United_Kingdom

Re: recalculate opportunity

Hello Susanne,

 

I'm sorry but I don't fully understand what you mean when you say:

"I am looking for a function to push the calculation of the Opportunity fields like GrossMargin."

 

Could you plaese provide a little bit more detail? I understand you are updating an opportunity through the SDK. What do you need to do after the update?

 

Kind regards,

 

 

Russell

 

Copper Contributor
Posts: 29
Country: Germany

Re: recalculate opportunity

Hallo Russell,

 

thanks for your feedback.

 

I have my own dialog showing the opportunity, click on the button update will update the opportunity via SDK in Act!.

Directly after this I try to get the GrossMargin value from the sdk for this opportunity, but it is still the old value.

 

Hope it is understandable now,

 

best regards Susanne

Solution
Accepted by sam_raikes (Copper Super Contributor)
‎09-25-2015 03:20 AM
Copper Super Contributor
Posts: 52
Country: United_Kingdom

Re: recalculate opportunity

[ Edited ]

Hi Susanne,

 

I can see your problem. I created my own opportunity dialog which I load an opportunity into and then add a product. Although it does update the opportunity, my dialog doesn't when I try and reload the properties/values from the Opportunity object.

 

It seems that it updates the database but doesn't update the Opportunity object you're referencing.

 

I've found a solution though. I load the opportunity into the dialog like this:

 

private void LoadOpportunity()
{
    name_tb.Text = o.Name;
    total_tb.Text = o.ProductTotal.ToString();

    string weighted = o.WeightedTotal.ToString();
    weighted = weighted.Substring(0, weighted.LastIndexOf(".") + 3);
    weighted_tb.Text = weighted;

    gross_tb.Text = o.GrossMargin.ToString();

    probability_tb.Text = o.Probability.ToString();

    process_tb.Text = o.Stage.Process.Name;
    stage_tb.Text = o.Stage.Name;

    if (o.Status == OpportunityStatus.Open) { open_rb.Checked = true; }
    else if (o.Status == OpportunityStatus.Won) { won_rb.Checked = true; }
    else if (o.Status == OpportunityStatus.Lost) { lost_rb.Checked = true; }
    else if (o.Status == OpportunityStatus.Inactive) { inactive_rb.Checked = true; }
}

 

I then add products to the opportunity like this:

 

private void AddProductToOpportunity(string productName, decimal cost, decimal price)
{
    OpportunityProduct oppProd = aFwk.Products.OpportunityProductManager.CreateCustomEntity();
    oppProd.Name = productName;
    oppProd.ItemNumber = productName;
    oppProd.Quantity = 1.00m;
    oppProd.Cost = cost;
    oppProd.Price = price;
    oppProd.Discount = 0.00m;
    oppProd.Update();

    o.UpdateProducts(new OpportunityProduct[] { oppProd }, null);
    o.Update();
}

 

Finally, I referesh the dialog like this:

 

private void refreshOpportunity()
{
    //create a guid arry containing just this opportunity
    List<Guid> guids = new List<Guid>();
    guids.Add(o.ID);
    Guid[] idArray = guids.ToArray();

    //set the opportunity to null
    o = null;

    //re-get the opportunity
    OpportunityList ol = aFwk.Opportunities.GetOpportunitiesByID(null, idArray);
    o = ol[0];

    //reload
    LoadOpportunity();
 }

 

The important part being that you null your reference to the opportunity and then obtain it again from the framework.

 

I hope this helps.

 

Kind regards,

 


Russell