Skip to main content

Notifications

How to access instance of class in form from COC of Datasource and Form controls.

GirishS Profile Picture GirishS 27,832 Super User 2024 Season 1

Hi All,

In this blog I will explain about how to access instance of class from COC.

Instance of class which are declared globally in the form cannot be accessed from COC.

To solve this issue, you can create one form method and return the class instance. Later you can use that method to get the buffer.

Let us assume there is a standard form available with the class instance declared globally.

public class FormName extension FormRun
{
    //global variables
    HcmWorkerHelper workerRecId;
    
    ///form and datasource methods will come here
}

Now create one form extension class and return that buffer which is declared globally.

[ExtensionOf(FormStr(FormName))]
internal final Class FormName_Extension
{
    public HcmWorkerHelper getWorkerRecId()
    {
        return workerRecId;
    }
}

Now you can call that method on the COC of Datasource or form controls. You can use that method in the event handler also to get the variable value.

[ExtensionOf(formDatasourcestr(FormName, DataSourceName))]
internal final class FormDatasourceName_Extension
{
    public void init()
    {
        HcmWorkerHelper workerRecIdDatasource;
        next init();
        workerRecIdDatasource = this.formRun().getWorkerRecId
    }
}

After formRun don't look for intelli sense to show the method name, just type in your method name manually.

Thanks.

Comments

*This post is locked for comments