Scheduler in System client

66 views
Skip to first unread message

Pritesh Shah

unread,
Apr 9, 2015, 3:41:56 AM4/9/15
to idem...@googlegroups.com
Hello,

I have scenario where I have created scheduler in System client executing on process created in report and process. When the process is executed, I am inserting/updating data into many tables. Now when inserting/updating records to multiple, I need to set the AD_Client_ID and AD_Org_ID to each record. As I have created scheduler in System Client process will be executed from System Client and context parameters will have AD_Client_D and AD_Org_ID of System which 0, 0 respectively, so I have set AD_Client_ID and AD_Org_ID by iterating over each Client and Org into Env as below
  • Env.setContext(getCtx(), "#AD_Client_ID", AD_Client_ID);
  • Env.setContext(getCtx(), "#AD_Org_ID",  AD_Org_ID);
Will above work when normal user would be accessing the idempiere from webui and creating records ?

What if I want to insert/update records in multiple client and org from single scheduler process ? If I create scheduler in each different client instead of System client and that scheduler will execute the same process java class then do I need to make Process synchronized by making doIt or custom method synchronized ?

Thanks in advance,

Pritesh

Nicolas Micoud

unread,
Apr 9, 2015, 3:53:28 AM4/9/15
to idem...@googlegroups.com
Hi,

in the doIt method, you can do something like  :

a sql statement like "select ad_client_id from ad_client where ...."
for (int ad_client_id : DB.getIDs) {
    your_method
(int ad_client_id)
}
return "ok";

Regards,

Nicolas

Pritesh Shah

unread,
Apr 9, 2015, 5:33:28 AM4/9/15
to idem...@googlegroups.com
Hello Nicolas,

Thank you for the instant reply.
What you have suggested is what I have done. My scenario is my scheduler which is executing the process is created in System Client so context variables will have AD_Client_ID and AD_Org_ID as 0 and I am explicitly setting AD_Client_ID and AD_Org_ID in the context by iterating a Client and Org loop similarly as you said, so Models when said get the AD_Client_ID and AD_Org_ID from Env. Will setting of AD_Client_ID and AD_Org_ID set explicitly in Env in process executed by Scheduler impact any other records saved by normal user from webui?

Thanks,
Pritesh

Nicolas Micoud

unread,
Apr 9, 2015, 5:39:09 AM4/9/15
to idem...@googlegroups.com
With my suggestion, you don't need to update context.

To pass the correct AD_Client_ID, you can do :

<your_object>.set_ValueNoCheck("AD_Client_ID", clientID);

Nicolas

Pritesh Shah

unread,
Apr 9, 2015, 9:10:00 AM4/9/15
to idem...@googlegroups.com
Hello Nicolas,

I completely agree with your suggestion. I can do, if I have only some models to set and update. Its large process and many models are updated dynamically, so explicitly set AD_Client_ID and AD_Org_ID looks difficult to me. Sure, if required we have to do it, but I was asking is, with the approach I have taken of setting AD_Client_ID in Env would work without any issue or it may issue like with normal transaction it will set different AD_Client_ID as Env was updated for normal users using Webui ?

Thanks,
Pritesh

redhuan d. oon

unread,
Apr 18, 2015, 4:29:13 AM4/18/15
to idem...@googlegroups.com
Hi Pritesh,
Env is a final class with its set and get methods as static. Certainly when you are iterating and mutating its values, other users or processes not related will be affected.
But if you have tested it in such a multi user environment without impact do share how you do it.

Pritesh Shah

unread,
Apr 21, 2015, 9:33:30 AM4/21/15
to idem...@googlegroups.com
I am working on it, I am testing from my end, but if you have any other alternative for the same or do you see what I have made cannot work please let me know.

According to me, Env ctx is created as per user session and should be different for each user.

redhuan d. oon

unread,
Apr 22, 2015, 1:21:55 AM4/22/15
to idem...@googlegroups.com
Thanks for correcting me. I am not that good in Java yet :>. Thus within that single user, the Env static variables would affect other processes going on likely in the background such as background accounts posting etc.
Reply all
Reply to author
Forward
0 new messages