Add new field for Proposed vendor changes workflow

Below are the steps required to create new fields in the vendor change work flow in D365 for finance and operation

Step 1. Create extension of VendTableChangeProposalField and add a enum. Say you want workflow for currency field of vendor add a enum with name currency

Step 2. Create post event handler or COC for VendTableChangeProposalFieldEnablement/InitializeAll method and add this line for your field

VendTableChangeProposalFieldEnablement::findOrCreate(VendTableChangeProposalField::Currency)

Step 3. Create extension of VendTableChangeProposal table and add Currency field and an enum filed IsChangedCurrency.

Step 3. Create vend change proposal form extension and add a new group for currency. This will enable to see your changes to currency filed in the proposal changes form from vendor form when workflow is activated

Step 4 . Create extension for vendChangePraposal form write the below code in disableDiscardbutton() method and ShowHideGroups() method

Step 5. Write the below code in Onclicked DiscardCurrencyChange button of form VendChangeProposal

[FormControlEventHandler(formControlStr(VendChangeProposal, DiscardCurrencyChange), FormControlEventType::Clicked)]
public static void DiscardCurrencyChange_OnClicked(FormControl sender, FormControlEventArgs e)
{
    FormRun                 formRunChangeProposal  = sender.formRun() as FormRun;
    FormDataSource          ChangeProposalFD       = formRunChangeProposal.findFirstFormDataSource(tableNum(VendTableChangeProposal));
    VendTableChangeProposal ChangeProposal         = ChangeProposalFD.cursor();
    ttsbegin;
    VendTableChangeProposal localRecord = VendTableChangeProposal::findByVendRecId(ChangeProposal.VendTable, true);
    localRecord.IsChangedCurrency = NoYes::No;
    localRecord.update();
    ttscommit;
    ChangeProposalFD.executeQuery();
}

Step 6 : Create extension for table VendTableChangeProposal and extend methods like isRedundant() and setFlagForChangedField() and event handler to update IsChangedCurrency field

///
/// </summary>
/// <param name="args"></param>
[PreHandlerFor(tableStr(VendTableChangeProposal), tableMethodStr(VendTableChangeProposal, update))]
public static void VendTableChangeProposal_Pre_update(XppPrePostArgs args)
{
    VendTableChangeProposal changeProposal = args.getThis();
    if (changeProposal.currency != changeProposal.orig().currency)
    {
        changeProposal.IsChangedCurrency = NoYes::Yes;
    }
}

public boolean isRedundant()
{
boolean ret = next isRedundant();
boolean Ischanged;
if (ret)
{
Ischanged = !(ret || this.IsChangedCurrency)
if(! Ischanged)//Do not delete the chage
{
ret = false;
}
}
}

public void setFlagForChangedField(VendTableChangeProposalField _controlledField)
{
next setFlagForChangedField(_controlledField);
switch(_controlledField)
{
case VendTableChangeProposalField::Currency :
this.IsChangedCurrency = NoYes::Yes;
break;

}

Step 7: Create extension for vendTable form and place the below code. Modified event on the currency would be captured and created as a change proposal for workflow

Step 8: The last step would to update the currency filed in the vendor table after the workflow, So create extension for VendTableChangePraposalApply and write the below code

Step 9. Done with the changes, test it in Vendor form



Hope this was helpfull

Thanks

Leave a comment