4 Replies Latest reply on Jul 11, 2019 10:23 PM by 3620098

    Remove Allergens of Output Material via Custom Code

    pnrajasekar

      Hi there,

      Requirement: To remove duplicates allergens via Custom Code (i.e. Save button click) based on the below priority.

      Priority #1 Known to Contain

      Priority #2 May Contain

      Priority #3 Doesn't Contain

       

      Implementation:

      Step #1:

      Step1.PNG

      Step #2:

       

      Step2.PNG

      Step #3:

      Step3.PNG

      Step #4:

      Step4.PNG

       

      Issue:

      The above implementation was partially successfully - but after SAVE, PLM system throws below exception. Here, if we refresh the screen manually then it's shows correctly (without duplicates) - I think PLM has some Refresh issue or Complete object wasn't deleted completely (bcoz in the exception, system is trying to fetch MaxPerUoM value but it couldn't get!)

      Exception.PNG

       

      Queries:

      How to get rid of this exception and load the correct value immediately after SAVE button click?

       

      Troubleshoot:

      Tried to refresh like below,

      specObject.Refresh(), - but no luck

       

      Please let me know if you need any other info from side to help us.

       

      PS: PLM Version: v6.2.2

       

      Regards,

      Raj

        • 1. Re: Remove Allergens of Output Material via Custom Code
          Ivy Zhu-Oracle

          Allergens objects are removed from parent IngrendientSpecification data object directly. But These removed allergens objects are stilled  in IngrendientSpecification business object. After save event, UI will reload removed allergens objects' maxPer100 parameters. It will lead to nullReferenceException error.

          To use IIngredientSpecBO replace IIngredientSpecification. Make sure ctx.Root is IIngredientSpecBO type object not IIngredientSpecification type object.

           

           

          In the code:

           

          ingSpecifiction = (IIngredientSpecification)ctx.Root

          • 2. Re: Remove Allergens of Output Material via Custom Code
            3620098

            1. Tried using the IngredientSpec business object, below is the sample code-

            IEnumerator en = null;
                        var specService = AppPlatformHelper.ServiceManager.GetServiceByType<ISpecificationService>();
                        var ingSpecBO = (IIngredientSpecBO)specService.CurrentBusinessObject;
                        IComplianceItemContainedBO complianceItemContainedBO = null;
                        en = ingSpecBO.AllergensPossiblyContained.GetEnumerator();
                       
                        try
                        {
                            while (en.MoveNext())
                            {
                                complianceItemContainedBO = (IComplianceItemContainedBO)en.Current;
                             
                                complianceItemContainedBO.SetMarkedAsDeleted(true, "Test");
                                complianceItemContainedBO.Delete();

                     

                            }
               
            2. Since the issue was the binding of maxper100gram, I tried manually giving some value to this as this was throwing a null reference exception just to test if it will make any difference, but still the object was null
               

               IUOMService uom = AppPlatformHelper.ServiceManager[typeof(IUOMService).FullName] as IUOMService;
                  while (en.MoveNext())
                            {
                                complianceItemContainedBO = (IComplianceItemContainedBO)en.Current;
                                IMeasurement measurement = (IMeasurement)complianceItemContainedBO.MaxPer100Grams.UOM;
                              
                                complianceItemContainedBO.SetMarkedAsDeleted(true, "Test");
                                complianceItemContainedBO.Delete();

                                complianceItemContainedBO.MaxPer100Grams = measurement;
                                complianceItemContainedBO.Comments = "Test";
                
                }

             

             


            Is there any service we can use to access the grid  of the Allergens and update the values, as in the error message looks like its trying the access the rowdatamodel to load the values.

             

            Kindly let me know if there is any correction to be done in the above code in case I have not done the way expected.
                           
               

            • 3. Re: Remove Allergens of Output Material via Custom Code
              Ivy Zhu-Oracle

              Validate extened funcation is used to extended validate for some parameters values not to add or remove objects.

              BTW, Does it get error if to save the specification in other tabs except compliance tab?

              • 4. Re: Remove Allergens of Output Material via Custom Code
                3620098

                When we save from other tabs, it does save but when we navigate to Compliance tab, we get a warning web page pop up with the exception message.