Storing value of checkbox in table

Hello,

I need to store the value of a checkbox on the Purchase Order Confirmation form. The check box is custom and I have added it to the PurchEditLines form (displayed there). 

So I have a field on the PurchParmUpdate table called CreditReference which has an EDT of NoYes and defaults as no. I am trying to send the new value of the checkbox when it is checked to PurchPurchaseOrderHeader.CreditReference. When I run that confirmation, it shows as a '0'.

Here are some code snippets that I use to run this.

Event Handler Class:

[PostHandlerFor(classStr(PurchPurchaseOrderDP), methodStr(PurchPurchaseOrderDP, processReport))]
    public static void PurchPurchaseOrderDP_Post_processReport(XppPrePostArgs args)
    {
        VendPurchOrderJour              vendPurchOrderJour;
        PurchPurchaseOrderDP            dpInstance = args.getThis() as PurchPurchaseOrderDP;
        PurchPurchaseOrderContract      contract = dpInstance.parmDataContract();
        PurchTable                      purchTable;
        PurchParmUpdate                 purchParmUpdate;
        VendTable                       vendTable;
        HcmWorker                       hcmWorker;
        HcmEmployeeEntity               hcmEmployeeEntity;
        PurchPurchaseOrderHeader        purchPurchaseOrderHeader = dpInstance.getPurchPurchaseOrderHeader();

        vendPurchOrderJour = VendPurchOrderJour::findRecId(dpInstance.parmPurchaseOrderContract().parmRecordId());
        //This if statement works as it should and gives me the correct value in Precision Forms
        if(vendPurchOrderJour.CostCenterDisplay != "")
        {
            ttsbegin;
            while select forupdate * from purchPurchaseOrderHeader
            {
                purchPurchaseOrderHeader.CostCenterDisplay = vendPurchOrderJour.CostCenterDisplay;
                purchPurchaseOrderHeader.write();
            }
            ttscommit;
        }
        //This one will go through the okay as Yes but will go through the 
        //purchPurchaseOrderHeader as No in Precision Forms
        if(purchParmUpdate.CreditReference == 1)
        {
            ttsbegin;
            while select forupdate * from purchPurchaseOrderHeader
            {
                purchPurchaseOrderHeader.CreditReference = purchParmUpdate.CreditReference;
                purchPurchaseOrderHeader.write();
            }
            ttscommit;
        }
    }
    
    [FormControlEventHandler(formControlStr(PurchEditLines, PurchParmUpdate_CreditReference), FormControlEventType::Modified)]
    public static void PurchParmUpdate_CreditReference_OnModified(FormControl sender, FormControlEventArgs e)
    {
        PurchParmUpdate                     purchParmUpdate;
        PurchPurchaseOrderHeader            purchPurchaseOrderHeader;
        FormRun                             fr = sender.formRun();
        FormControlCancelableSuperEventArgs cancelArgs = e as FormControlCancelableSuperEventArgs;
        FormCheckBoxControl                 formCheckboxCredRef = sender as FormCheckBoxControl;

        if(formCheckboxCredRef.checked())
        {
            info("Credit Reference will be printed");
            
            select * from purchPurchaseOrderHeader
                join purchParmUpdate
                where purchParmUpdate.PurchId_SA == purchPurchaseOrderHeader.PurchId;

            purchParmUpdate.CreditReference = enum2int(NoYes::Yes);
        }else
        {
            info("Credit Reference will not be printed");

            select * from purchPurchaseOrderHeader
                join purchParmUpdate
                where purchParmUpdate.PurchId_SA == purchPurchaseOrderHeader.PurchId;

            purchParmUpdate.CreditReference = enum2int(NoYes::No);
        }
    }
    
    [FormControlEventHandler(formControlStr(PurchEditLines, OK), FormControlEventType::Clicked)]
    public static void OK_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        PurchPurchaseOrderHeader    purchPurchaseOrderHeader;
        PurchParmUpdate             purchParmUpdate;
        FormRun                     fr = sender.formRun() as FormRun;

        select * from purchPurchaseOrderHeader
                join purchParmUpdate
                where purchParmUpdate.PurchId_SA == purchPurchaseOrderHeader.PurchId;
        info(enum2Str(purchParmUpdate.CreditReference));
        info(enum2Str(purchPurchaseOrderHeader.CreditReference));
        purchPurchaseOrderHeader.validateWrite();
    }

Contract Extension Class:

[ExtensionOf(classStr(PurchPurchaseOrderContract))]
final class PurchPurchaseOrderContract_Extension
{
    public CreditReference CreditReference;

    [DataContractAttribute('CreditReference')]
    public boolean parmCreditReference(CreditReference _creditReference = CreditReference)
    {
        CreditReference = _creditReference;
        return CreditReference;
    }

}

Controller Extension Class:

[ExtensionOf(classStr(PurchPurchaseOrderController))]
final class PurchPurchaseOrderController_Extension
{
    protected void modifyContract()
    {
        PurchPurchaseOrderContract  purchPurchaseOrderContract = contract as PurchPurchaseOrderContract;
        PurchPurchaseOrderHeader    purchPurchaseOrderHeader;
        CreditReference             creditReference;
        next modifyContract();
        
        creditReference = this.getCreditReference(purchPurchaseOrderHeader.PurchId);
        purchPurchaseOrderContract.parmCreditReference(creditReference);
    }

    public CreditReference getCreditReference(PurchId _purchId)
    {
        PurchPurchaseOrderHeader    purchPurchaseOrderHeader;
        PurchParmUpdate             purchParmUpdate;

        select * from purchPurchaseOrderHeader
            join purchParmUpdate
            where purchParmUpdate.PurchId_SA == purchPurchaseOrderHeader.PurchId;
        if(purchPurchaseOrderHeader.CreditReference == purchParmUpdate.CreditReference)
        {
            info("Header and Update are the same");
        }else
        {
            info("Nope");
        }

        return purchPurchaseOrderHeader.CreditReference;
    }

}

I also have a CreditReference field on the PurchTable but not sure if I need that.

Why isn't the value being saved in the PurchPurchaseOrderHeader table? I am also looking for advice on what isn't necessary to have in my existing code. For example any classes or methods that I have included to show.

Parents
No Data
Reply
  • Everything is running through the PurchPurchaseOrderHandler class.

    class PurchPurchaseOrderHandler
    {
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        [PreHandlerFor(formStr(PurchEditLines), formMethodStr(PurchEditLines, run))]
        public static void PurchEditLines_Pre_run(XppPrePostArgs args)
        {
            SysGlobalObjectCache purchEditLinesCache = classFactory.globalObjectCache();
            purchEditLinesCache.remove(classStr(PurchPurchaseOrderHandler),[curUserId()]);
        }
    
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        [PostHandlerFor(formStr(PurchEditLines), formMethodStr(PurchEditLines, closeOk))]
        public static void PurchEditLines_Post_closeOk(XppPrePostArgs args)
        {
            FormRun fr = args.getThis();
            SysGlobalObjectCache    purchEditLinesCache = classFactory.globalObjectCache();
            FormCheckBoxControl creditReference = fr.design().controlName(formControlStr(PurchEditLines, CreditReference)) as FormCheckBoxControl;
            boolean checkBoxValue = creditReference.value();
    
            // add the checkbox value to container. Keep adding multiple values to the container.
            // so for another checkbox value, the last parameter would look like [checkboxValue,AnothercheckboxValue]
            purchEditLinesCache.insert(classStr(PurchPurchaseOrderHandler),[curUserId()],[checkBoxValue]);
        }
    
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [DataEventHandler(tableStr(VendPurchOrderJour), DataEventType::Inserting)]
        public static void VendPurchOrderJour_onInserting(Common sender, DataEventArgs e)
        {
            VendPurchOrderJour     vendPurchOrderJour = sender as VendPurchOrderJour;
            SysGlobalObjectCache    purchOrderCache = classFactory.globalObjectCache();
            int                     companyImageDefault;
    
            // conpeek's last parameter 1 defines what element is extracted from the container.
            // For all other fields, use the index/position of the checkbox value when it was inserted in the cache.
            vendPurchOrderJour.CreditReference = conpeek(purchOrderCache.find(classStr(PurchPurchaseOrderHandler),[curUserId()]), 1);
        }
    
        /// <summary>
        /// Fill in Extra fields needed for Purchase confirmation documents
        /// </summary>
        /// <param name="args"></param>
        [PostHandlerFor(classStr(PurchPurchaseOrderDP), methodStr(PurchPurchaseOrderDP, processReport))]
        public static void PurchPurchaseOrderDP_Post_processReport(XppPrePostArgs args)
        {
            VendPurchOrderJour              vendPurchOrderJour;
            PurchPurchaseOrderDP            dpInstance = args.getThis() as PurchPurchaseOrderDP;
            PurchPurchaseOrderContract      contract = dpInstance.parmDataContract();
            PurchTable                      purchTable;
            PurchLine                       purchLine;
            HcmWorker                       hcmWorker;
            PurchPurchaseOrderHeader        purchPurchaseOrderHeader = dpInstance.getPurchPurchaseOrderHeader();
            PurchPurchaseOrderTmp           purchPurchaseOrderTmp    = dpInstance.getPurchPurchaseOrderTmp();
    
            vendPurchOrderJour = VendPurchOrderJour::findRecId(dpInstance.parmPurchaseOrderContract().parmRecordId());
    
            if(vendPurchOrderJour.CreditReference == 1)
            {
                ttsbegin;
                while select forupdate * from purchPurchaseOrderHeader
                {
                    purchPurchaseOrderHeader.CreditReference = vendPurchOrderJour.CreditReference;
                    purchPurchaseOrderHeader.write();
                }
                ttscommit;
            }
        }
    
    }

Children
No Data
Related
Recommended