Thursday, July 13, 2023

adding new node in hierarcy type in workflow



class: WorkflowHierarchyProviderHelper  for convert nodetype 


[ExtensionOf(classstr(WorkflowHierarchyProviderHelper))]

public  final class testWorkflowHierarchyProviderHelper_Extension

{

    public anytype convertToNodeDataType(extendedDataTypeName _dataType, anytype _value, WorkflowContext _workflowContext)

    {

        HcmPersonnelNumberId    personnelNumberId;


        const extendedDataTypeName ProjResponsibleFinancialWorker = 'ProjResponsibleFinancialWorker';

        const extendedDataTypeName PurchReqPreparerRefRecId       = 'PurchReqPreparerRefRecId';


        if (_dataType == ProjResponsibleFinancialWorker)

        {

            _dataType = PurchReqPreparerRefRecId;

        }


        personnelNumberId = next convertToNodeDataType(_dataType, _value, _workflowContext);


        if (_dataType == ProjResponsibleFinancialWorker)

        {

            _dataType = ProjResponsibleFinancialWorker;

        }


        return personnelNumberId;

    }


}

class: WorkflowHierarchyProviderHelperEventHandler for adding node "Controller"



public final class TestWorkflowHierarchyProviderHelperEventHandler

{


    [SubscribesTo(classstr(WorkflowHierarchyProviderHelper), delegatestr(WorkflowHierarchyProviderHelper, addAdditonalSupportedDataTypesDelegate))]

    static void addAdditonalSupportedDataTypesDelegate(Set _supportedDataTypes)

    {

        _supportedDataTypes.add(extendedTypeStr(ProjResponsibleFinancialWorker));

    }


}

Apply ranges while opening the SalesTeableListpage form in D365 FO

  let's assume that i have an requirement while opening the list page form. I want to filter the form based on which status is invoiced.

[ExtensionOf(classStr(SalesTableListPageInteraction))]

final class SalestableListpageInteraction_Extension

{

     public void initializeQuery(Query _query)

    {

        next initializeQuery(_query);

        var qbds = _query.dataSourceTable(tableNum(SalesTable));

        qbds.addRange(fieldNum(SalesTable,SalesStatus)).value(queryValue(SalesStatus::Invoiced));

    }




Restrict the user to open the particular Form, if the same form already opened by any other user.

 In my scenario when I open particular SalesOrder i want to restrict to others by throwing an error “The same Salesorder is already opened by any other user”



1. Firstly add one field in SalesTable. 
2. Navigation  AOT -> Tables -> SalesTable.
3.Create new field  userId Datatype is string.

Navigate to Forms\SalesTable\Methods\init, write the following code in it.
public void init()
{
 
         SalesTable    salestablecpy ;
         FormRun       callerForm;

        salestablecpy  = element.args().record();
        callerForm       = element.args().caller();

        If (!salestablecpy.UserId)
        {
            ttsBegin;

                 salestablecpy.UserId = curUserId();
                  salestablecpy.doUpdate();
            ttsCommit;
        
        }
       else if(salestablecpy.UserId != curUserId())
       {
      
            throw error(strFmt("The same Salesorder(%1) is already opened by %2",                                                                 salestablecpy.SalesId,salestablecpy.UserId));

       }
}

. Similarly, navigate to  Forms\SalesTable\Methods\Close,  write the following code in it.




void  close()
{  
        SalesTable    salestablecpy, saleesTableLoc  ;
        formrun      formrun ;

       salestablecpy = element.args().record();

       formrun = element.args().caller();

      if (salestablecpy.UserId)
      { 
           ttsBegin;

           select forUpdate saleesTableLoc  where saleesTableLoc.RecId==salestablecpy.RecId;
           saleesTableLoc.UserId = ' ';
           saleesTableLoc.doUpdate();

           ttsCommit;
   
    }

}

Disable Main account

 in my scenario where I need to lock the main account .user should not be able to Enter the value in account distribution.

below code works 

 [FormEventHandler(formStr(AccountingDistribution), FormEventType::Initialized), SuppressBPWarning('BPParameterNotUsed', "Parameter not required")]

    public static void AccountingDistribution_OnInitialized(xFormRun sender, FormEventArgs e)

    {   

             const str segmentedControl = 'Distribution_LedgerDimension';

            SegmentedEntryControl  dimControl = sender.design().controlName(segmentedControl);

            dimControl.parmLockMainAccountSegment(true);

        

    }

Wednesday, July 12, 2023

Event Handlers

 Form event handler: 

OnInitialized:
// Form  - event handler for form OnInitialize
    [FormEventHandler(formStr(FormName), FormEventType::Initialized)]
    public static void FormName_OnInitialized(xFormRun sender, FormEventArgs e)
    {

        FormDataSource DataSourceName_ds = sender.dataSource(formDataSourceStr(FormName, DataSourceName));
            //Or
        FormDataSource DataSourceName_ds = sender.dataSource('DataSourceName');

    }



Closing:
   
// form- event handler for form closing
    [FormEventHandler(formStr(FormName), FormEventType::Closing)]
    public static void FormNamee_OnClosing(xFormRun sender, FormEventArgs e)
    {
        FormDataSource datasource_ds    = sender.dataSource(formDataSourceStr(FormName, DataSourceName));
        TableName      buffTable        = datasource_ds.cursor();
    }


Datasource event handler:

initValue:

// Datasource - EventHandler for datasource initvalue
    [FormDataSourceEventHandler(formDataSourceStr(FormName, DataSourceName), FormDataSourceEventType::InitValue)]
    public static void DataSourceNames_OnInitValue(FormDataSource sender, FormDataSourceEventArgs e
    {
        FormRun          formRun             = sender.formRun();
        FormDataSource   DataSourceName_ds   =                                                         formRun.dataSource(formDataSourceStr(FormName,DataSourceName)) as FormDataSource;
                                //(or)
        FormDataSource   DataSourceName_ds = send as formdatasource  ;  
        TableName        buffTable           = DataSourceName_ds.cursor();
    }


DataSource field Level 

Modified

[FormDataFieldEventHandler(formDataFieldStr(HcmWorkerEnrollment, HcmWorkerEnrolledBenefit,   Benefit), FormDataFieldEventType::Modified)]
 public static void Benefit_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
 {
     FormDataSource   fd      = sender.datasource();
     table            buffer  = fd.cursor();
     FormRun         formRun  = fd.formRun();

    FormRealControl     amount = formRun.design().controlNam('ControlName');
        
}

Form Control 
Clicked ()

[FormControlEventHandler(formControlStr(HcmWorkerEnrollment, ControlName), FormControlEventType::Clicked)]
public static void Controlname_OnClicked(FormControl sender, FormControlEventArgs e)
{
FormRun  formRun = sender.formRun();
        FormDataSource   FormDataSource_ds = formRun.dataSource(formDataSourceStr(HcmWorkerEnrollment,                   DataSourceName));
        Table  Buffer = FormDataSource_ds.cursor();
}

adding new node in hierarcy type in workflow

class: WorkflowHierarchyProviderHelper  for convert nodetype  [ExtensionOf(classstr(WorkflowHierarchyProviderHelper))] public  final class ...