formdatasource.queryRun()

Hi,

Can anyone please suggest me how to do the below requirement.

There is a method written in PO form - button click method. The argument passed from the PO form - button click method is “element”. For example :- Classname.method(element);

Here, I need to call the same method written in button click from the class. When I do this functionality, I could find SysSetupFormRun is being passed as argument for both cases(Clicking button (or) calling through class).

Following is the code written by me in class to call the method written in PO form - button click method.

Args args;
FormRun formRun;
Object formRunObject;

args = new Args();
args.name(formstr(PurchTable));
args.menuItemName(menuitemdisplaystr(PurchTable));
args.record(_purchTable);
formRun = classfactory.formRunClass(args);
formRun.init();
fds = formRun.dataSource();
formRunObject = formRun;

ClassName.getFormDataSource(formRunObject);

The below is the method available in class that’s been called from PO form - button click method.

FormDataSource getFormDataSource(FormRun _callerFormRun)

{

FormDataSource callerFormDataSource;

FormDataSource fds;

Object selectedControl;

selectedControl = _callerFormRun.selectedControl();

fds = SysFormDataSource::fdsId2fds(_callerFormRun,selectedControl.dataSource());
if (fds && fds.queryRun() )
return fds;

}

When the above method is called from PO form - Button click method, it returns fds but not when called from class method. I mean fds.queryRun() fails when called from class.

How to pass the argument from the class - method to get fds.queryRun() and return formDataSource. Thank you.

You would have to call formRun.run() first to get fds.queryRun() intialized.

Hi Martin,

Thank you very much. It works well. Is it possible to get fds.queryRun() without calling formRun.run();… I use it in a batch job, I can use formRun.close() to close the form but it wouldn’t be nice to open the form everytime batch runs… Thank you.

You can’t - the QueryRun instance is in run().

You also can’t run forms from normal (= server-bound) batches. Calling business logic through a form is usually a bad idea anyway.

Extract the code you want to call to a class and call the class from your batch. About QueryRun, don’t take it from the form - create a new instance in your code.

Hi Martin,

Thank you. I called the necessary code of the class from my batch job but I need to pass fds.queryRun() from my batch job to complete the entire process successfully. Could you let me know how to do it?

You can’t.

Please tell us what you’re trying to achieve (from a high-level perspective) so we can suggest a solution that can be done.

Hi Martin,

I have a requirement to approve a PO using batch job. In click method of Approve button in PO form, the following code is available,

approvalCycle.approve(element);

This approve method code leads to Classes\EventCreateRule\findValidCallerDS. It returns formdatasource when accessing this below code.

if (EventBuildValidAlertFields::isControlTypeValid(selectedControl) && selectedControl.dataSource())
{
fds = SysFormDataSource::fdsId2fds(callerFormRun,selectedControl.dataSource());
if (fds && fds.queryRun() && this.eventBuildValidAlertFields(fds).parmTmpEventAlertField().RecId)
return fds;
else if (fds)
invalidDSCon += fds.id();
}

When I call the same method – approvalCycle.approve(formRun); – from batch job, fds.QueryRun() is failed and I’m not able to proceed further. Please let me know how can I get fds, when passed from batch job class. Thank you.

As I understand, you have activated change management and want to run approval item of the workflow from a batch.

I would challenge the whole idea of approval by a batch - if it’s approved automatically, it’s the same as if there was no approval at all. You could change the workflow not to require approval or disable it completely.

If you want to run the step by yourself anyway, look at your approval (AOT > Workflow > Approval), find the Approve outcome and see the ActionMenuItem property. For example, it’s PurchTableApprovalApprove menu item for PurchTableApproval. You still won’t be able to run the menu item from a batch, because it would show a dialog (and there wouldn’t be any user to fill it in), but it will show you the code you have to call.

Hi Martin,

It’s not a workflow but new requirement done earlier. Could you tell me how to get formdatasource.queryRun() from a class? Thank you.