10 Replies Latest reply: Apr 9, 2014 11:10 AM by KellyMayfield Branched from an earlier discussion. RSS

Re: Formulation Inputs Costs

VSalas Newbie
Currently Being Moderated

Hi Ron,

 

When doing the following:

 

public string GetText(IFormatPluginContext context)

{

     FormulationCostContext<IFormulationInputDO> costContext = (FormulationCostContext<IFormulationInputDO>)context.Context;

....

 

I only have access to one formulation input of the Formula (it is always the last input); is there a way that I can obtain a list of the formulation inputs and from there look for the costs options and return the highest cost per input?

 

Also, since the GetText method returns a single string, how can I be able to assign the desired cost to each formulation input material?

 

Thank you.

 

-Victoria.

  • 1. Re: Formulation Inputs Costs
    Ron M Pro
    Currently Being Moderated

    Hi Victoria,
    For some reason, I did not see this entry on the forum - I think it wasn't created as a question, maybe.

     

    The plugin should be getting called for each Input, not just the last one. Each input should call be getting called for the "FormulationInputCostBookPriceOverride" format plugin extensibility point.

    Can you verify?

     

    Thanks,

    Ron

  • 2. Re: Formulation Inputs Costs
    VSalas Newbie
    Currently Being Moderated

    Hi Ron,

     

    Yeah, the GetText method receives a context, which should be of the type FormulationCostContext<IFormulationInputDO> when using FormulationInputCostBookPriceOverride extension point. However, in order to call the GetText method for each input, I should first know the formulation spec, and this is what I don't know how to do.

     

    And after getting the formulation spec, I suppose I will do a loop through the inputs and then call GetText() each time?

     

    Thank you!

     

    -Victoria

  • 3. Re: Formulation Inputs Costs
    Ron M Pro
    Currently Being Moderated

    The GetText will get called automatically by PLM4P for each formulation input, so you should not loop through the inputs of the formulation spec can call GetText. This is done for you.

     

    For example, if your Formulation has 3 inputs, A, B, and C, the cost for each input get called through the plugin, one at a time:

    - Input A - GetText (Object = IFormulationInputDO - A)

    - Input B - GetText (Object = IFormulationInputDO - B)

    - Input C - GetText (Object = IFormulationInputDO - C)

     

    If you are going to just load the costs from the cost library for each, then you shouldn't need the Formulation Spec, since you can call the CostLibraryService. I described this in the earlier discussion (Re: Formulation Inputs Costs)

     

    If you really do need the Formulation Spec itself, you should be able to use the Specification Service to get it, using the Current property for the Data object of the CurrentBusinessObject for the business object.

    private static ISpecificationService SpecService

    {

       get

       {

         return AppPlatformHelper.ServiceManager.GetServiceByType<ISpecificationService>();

       }

    }

    But, again, if you just need to find a highest cost from the cost book, you should be able to call the CostLibraryService like I described.

  • 4. Re: Formulation Inputs Costs
    VSalas Newbie
    Currently Being Moderated

    Hi Ron,

     

    Sorry to bother you again. I'm getting an error when implementing the plugin code. Below is a snippet of my GetText code:

     

    public string GetText(IFormatPluginContext context)

    {

      FormulationCostContext<IFormulationInputDO> costContext = (FormulationCostContext<IFormulationInputDO>)context.Context;

      ...

      ...

      costType = costContext.CostPreferences.CostType;

      facilityPkId = costContext.CostPreferences.CostSet.PKID;

      materialPkId = costContext.Object.Material.PKID;

      ...

      ...

      return highestCost.ToString();

    }

     

    The problem is that whenever I select different cost preferences (Cross Reference, Cost Type or Plant) from the drop down menu, I get the following error:

     

    ErrorType: Primary| ErrorCount: 1| App: GSM| SessionId: daa1a7cc-116f-1bb8-ae5f-0fcea6b61b78| UserId: prodikaadmin| IsNewSession: False| ServerID: fe80::1412:ecb7:fcbf:89b0%11| Misc: Spec 5000010-001 ; test ; EditMode|

    Exception: System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.NullReferenceException: Object reference not set to an instance of an object.

       at CustomPlugins.HighestCostPluginFactory.HighestCostPlugin.GetText(IFormatPluginContext context)

       at Xeno.Prodika.PluginExtensions.Helpers.FormatPluginHelper.GetTextFromPlugin(String pluginName)

       at Xeno.Prodika.GSMLib.Formulation.DomainModel.FormulationInputBase.get_ItemCost()

       at Xeno.Prodika.GSMLib.Formulation.DomainModel.IngredientFormulationInputFactory.IngredientFormulationInput.get_ItemCost()

       at Xeno.Web.UI.GSMExtensions.Formulation.Steps.Process.InputGrid.FormulationInputCostHelper.CalcCostPer(Object inputItem)

       at Xeno.Web.UI.GSMExtensions.Formulation.Process.ctlFormulationInputs.GetCalculatedCostPer(IFormulationInput formulationInput)

       at ASP.gsmextensions_formulation_process_ctlformulationinputs_ascx.__DataBinding__control77(Object sender, EventArgs e)

     

    I already tried commenting all the code from the GetText method and just returning "0.00" and everything works fine, but when I try to print a field on a text file to see it's value, for instance costContext.CostPreferences.CostSet.PKID, I also get the error. So I don't know if it's because the way I'm accessing the properties or I'm just missing something.

     

    I would really appreciate your help.

     

    Thanks in advance.

     

    -Victoria.



  • 5. Re: Formulation Inputs Costs
    Ron M Pro
    Currently Being Moderated

    So when you are debugging, are you seeing the costContext.CostPreferences.CostSet is null? If so, can you verify that you have selected a facility/plant for the cost set, or is that drop down empty?

  • 6. Re: Formulation Inputs Costs
    VSalas Newbie
    Currently Being Moderated

    Hi Ron, thanks for responding

     

    If I already have some cost preferences saved, the values are being printed on the text file correrctly, but if I go to edit mode and change some value from the cost preferences, I get the error on the UI.

     

    I also tried to put my code in a try/catch block so I can get the error stack trace on my text file, but I'm not getting anything, so that means that when it is in edit mode and I change something it is not even accesing the GetText method.

     

    Thank you.

     

    -Vicky

  • 7. Re: Formulation Inputs Costs
    Ron M Pro
    Currently Being Moderated

    Sounds like it could be a bug. Please submit an SR with Support, and be sure to reference this forum posting.

     

    Thanks

  • 8. Re: Formulation Inputs Costs
    Ron M Pro
    Currently Being Moderated

    Vicky,

    We had a developer reproduce it, but it is only throwing a null reference if there is no cost set and/or cost type selected. If so, then you should just need to add a null check before accessing the CostSet's properties.

  • 9. Re: Formulation Inputs Costs
    VSalas Newbie
    Currently Being Moderated

    Thank you Ron!

     

    I added the null checks to all the parameters and it seems to be working now

  • 10. Re: Formulation Inputs Costs
    KellyMayfield Expert
    Currently Being Moderated

    We now offer a reference implementation that allows you to pull the most expensive cost.  You can learn more about it in EP 3.9

    Agile Product Lifecycle Management for Process Extensibility Pack v3.9