Showing posts with label dynamics365operations. Show all posts
Showing posts with label dynamics365operations. Show all posts

Tuesday, 8 August 2017

Display method in Dynamics 365 for operations

Hi All,
This posts helps you to understand and create a "display"  method for the table extension.
Lets say, the requirement is to add a method in the standard table, it can be achieved either by creating a table extension.
So in this scenario we had a requirement to add a display method in the standard table "CustTrans".
In Dynamics 365 we wont be able to add the new method or modify the existing method to the standard table or to an extension table.
It can be achieved by using the extension class.
Step 1: Create a new class and name it as <Classname>_<Extension>.
<Class-name> - can be any name, but it is preferred to give the table name for which the extension is being created. 
postfix <_Extension> is must.
public static class CustTrans_Extension
{
}
Step 2 : Now add the display methods in the class which is required to be shown.
public static class CustTrans_Extension
{
[SysClientCacheDataMethodAttribute(true)]
public static display AgreementId agreementId(CustTrans _this)
{
LedgerJournalTrans ledgerJournalTrans;
select ledgerJournalTrans
where ledgerJournalTrans.TransactionType == LedgerTransType::Payment &&
LedgerJournalTrans.CustTransId == _this.RecId;

return ledgerJournalTrans.AgreementId;
}
}
Step 3: To use this display method in the form.
Create a string control in the form design and set the following properties
Data source: CustTrans
DataMethod: CustTrans_Extension::agreementId
CacheDataMethod: Yes
Below is the screen shot for reference.
Step 4: Build/Rebuild the project/solution and check the output in the URL.

Thursday, 3 August 2017

Number sequence in Dynamics 365









                                                1.Create a new  EDT string: StudentID






2.  Create a new Table : MK_Seq

3.  Add EDT and fields into the  Table: MK_Seq





4.Create Form MK_Seq








5.Create a new method (numberSeq) for Table MK_Seq


Write the below code in that method
                                                            public class MK_NumSeq extends common
{
                                        /// <summary>
                 ///
    /// </summary>
    static NumberSequenceReference numberSeq()
    {
        return NumberSeqReference::findReference(extendedTypeNum(StudentID));
    }

}


6.Create a new class (numseqStudent) and make extends with NumberSeqApplicationModule


class numseqStudent extends NumberSeqApplicationModule
{
    public void initializeReference(NumberSequenceReference _reference,
         NumberSeqDatatype _datatype, NumberSeqScope _scope)
    {
        #ISOCountryRegionCodes
        super(_reference, _datatype, _scope);
        switch (_datatype.parmDatatypeId())
        {
            case extendedTypeNum(StudentID):
           if("USA")
                {
                    _reference.AllowSameAs = true;
                }
        }
    }
    protected void loadModule()
    {
        NumberSeqDatatype datatype = NumberSeqDatatype::construct();
        datatype.parmDatatypeId(extendedTypeNum(StudentID));
        datatype.parmReferenceHelp(literalStr("@studentlable:StudentID"));
        datatype.parmWizardIsManual(NoYes::No);
        datatype.parmWizardIsChangeDownAllowed(NoYes::No);
        datatype.parmWizardIsChangeUpAllowed(NoYes::No);
        datatype.parmWizardHighest(999999);
        datatype.parmSortField(1);
        datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
        this.create(datatype);
    }
    public NumberSeqModule numberSeqModule()
    {
        return NumberSeqModule::Vend;
    }
    [SubscribesTo(classstr(NumberSeqGlobal),delegatestr(NumberSeqGlobal,buildModulesMapDelegate))]
    static void buildModulesMapSubsciber(Map numberSeqModuleNamesMap)
    {
        NumberSeqGlobal::addModuleToMap(classnum(numseqStudent), numberSeqModuleNamesMap);
    }

}


7.Write a job and run that

class Studentjob
{       
   
    public static void main(Args _args)
    {  
        numseqStudent numberSeqModuleRisk = new numseqStudent ();
            numberSeqModuleRisk .load();
    }
}



8.Then run the wizard   Organization Administration -> CommonForms -> Numbersequences -> Numbersequences -> Generate -> run the wizard.





9.Go to Account Payable-> setup -> Account Payable parameters form -> Num Seq.




10. Now create methods as shown on Form below



11.Write below code in  form method code
    

[Form]
public class MK_Seq extends FormRun
{
    NumberSeqFormHandler numberSeqFormHandler;
    NumberSeqFormHandler numberSeqFormHandler()
    {
        if (!numberSeqFormHandler)
        {
numberSeqFormHandler=NumberSeqFormHandler::newForm(MK_NumSeq::numberSeq().NumberSequenceId,  element,MK_NumSeq_ds , fieldNum(MK_NumSeq, StudentID));
        }
        return numberSeqFormHandler;
    }

    public void close()
    {
        if (numberSeqFormHandler)
        {
            numberSeqFormHandler.formMethodClose();
        }
        super();
 }




12.Write below code in form datasource method code.

class MK_NumSeq
    {
      
        public void create(boolean _append = falseboolean _extern = false)
        {
            element.numberSeqFormHandler().formMethodDataSourceCreatePre();
            super(_append);
            if (!_extern)
            {
                element.numberSeqFormHandler().formMethodDataSourceCreate(true);
            }
        }

        public void write()
        {
            super();
            element.numberSeqFormHandler().formMethodDataSourceWrite();
        }

        public boolean validateWrite()
        {
            boolean         ret;
            ret = super();
            ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(ret) && ret;
            if (ret)
            {
                MK_NumSeq.validateWrite();
            }
            return ret;
        }

        public void linkActive()
        {
            element.numberSeqFormHandler().formMethodDataSourceLinkActive();
            super();
        }

        public void delete()
        {
            element.numberSeqFormHandler().formMethodDataSourceDelete();
            super();
        }

    }


13.Now our custom number sequence is generated. Open your Form and check Num Seq by creating new record on your filed.