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?
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?
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
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.
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;
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.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.
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.