Business Partner Quick Entry - how to set User Name equal to BP Name in a callout?

166 views
Skip to first unread message

Stanislav Karakhanov

unread,
Nov 20, 2014, 7:36:03 PM11/20/14
to idem...@googlegroups.com
Hi, Everybody!

I need to do the following.
When entering new BP using Quick Entry window after user enters BP name I need to set User Name equal to BP Name.
I thought this would be an easy task but the difficulty is that these fields are on different tabs.
And in my callout for "BP Name" (MBPartner.COLUMNNAME_Name) I can't access the field "User Name" which is on a different tab.
mTab.getFields()   gives me only the fields from the BP tab.

So far I couldn't find the way to do the task.
Could somebody please help me with that?

redhuan d. oon

unread,
Nov 21, 2014, 5:58:57 PM11/21/14
to idem...@googlegroups.com
It should be easy. Creating a foreign table record from scratch. How did you do the Callout? Show me your code.

Eduardo Gil

unread,
Nov 21, 2014, 6:15:51 PM11/21/14
to idem...@googlegroups.com
Hi Stanislav.

It sould not be a problem beacuse you can program any CRUD operation in the callout process, by executing an sql statement. For example i have been seen a callout that create order line with a field created for read barcode of product. But the problem you really have is tha the bp record is not created and the user could not be related to the bp.

I recomend to you to extend afterSave Model of MBPartener after save and create the user information with the same of business partner.

Regards,

Stanislav Karakhanov

unread,
Nov 21, 2014, 7:01:46 PM11/21/14
to idem...@googlegroups.com
Hello, Redhuan!
Thank you for participation.
Well, I've made a callout in a plug-in using IColumnCalloutFactory.
(Many thanks to Jan Thielmann for his fundamental videos!)

May be there is a way to get Window class from WindowNo. I haven't managed to find the appropriate method so far.
So, currently the code is as follows.

//----------------------------------------------
package org.infora.callouts;

import java.util.Properties;

import org.adempiere.base.IColumnCallout;
import org.adempiere.webui.session.SessionManager;
import org.compiere.model.GridField;
import org.compiere.model.GridTab;
import org.compiere.model.MBPartner;
import org.compiere.model.MUser;
import org.compiere.util.CLogger;
import org.compiere.util.Env;

public class BPcallout implements IColumnCallout {

    @Override
    public String start(Properties ctx, int WindowNo, GridTab mTab,
            GridField mField, Object value, Object oldValue) {
       
        CLogger log = CLogger.getCLogger(BPcallout.class);
        if ("Y".equals(Env.getContext(ctx, WindowNo, "_QUICK_ENTRY_MODE_"))) {
            if (mField.getColumnName().equalsIgnoreCase(MBPartner.COLUMNNAME_Name)) {
                ///
                System.out.println("BPcallout.start ctx="+ctx.toString());
                //log.warning("BPcallout.start ctx="+ctx.toString());
                GridField[] fld = mTab.getFields();
                System.out.println("Fields:");
                for (GridField f : fld ) {
                    System.out.println(f.getColumnName()+"="+f.getValue());
                }
                System.out.println("windowno="+WindowNo);
                //Env.get
            }
        }
        return null;
    }

}
//------------------------------------



суббота, 22 ноября 2014 г., 1:58:57 UTC+3 пользователь redhuan d. oon написал:

Stanislav Karakhanov

unread,
Nov 21, 2014, 7:19:08 PM11/21/14
to idem...@googlegroups.com
Hi Eduardo!
Thanks for helping.
Well, I thought that I could manipulate just the window elements, as all the fields are already in one Quick Entry window.
In regard of issuing SQL statements - yes you've pointed right at the problem - what if the user presses Cancel thus not saving anything in db?


> I recomend to you to extend afterSave Model of MBPartener after save and create the user information with the same of business partner.

Actually, I wanted a bit more sophisticated logics here, that is:
after the user enters "BP Name" field the "User Name" field gets filled in ( = BP Name), but later (down the window :-))) the user can change User Name field if needed.

The task is mostly about usabilty and seemed to be quite simple.



суббота, 22 ноября 2014 г., 2:15:51 UTC+3 пользователь Eduardo Gil написал:

Carlos Antonio Ruiz Gomez

unread,
Nov 22, 2014, 12:37:57 PM11/22/14
to idem...@googlegroups.com
Hi Stanislav, I added the method GridTab.getGridWindow with:
https://idempiere.atlassian.net/browse/IDEMPIERE-2331

With this your callout will work easily as:

        if (value == null)
            return null;

        if ("Y".equals(Env.getContext(ctx, WindowNo, "_QUICK_ENTRY_MODE_"))) {
            if (mField.getColumnName().equalsIgnoreCase(MBPartner.COLUMNNAME_Name)) {
                ///
                for (int i=0; i<mTab.getGridWindow().getTabCount(); i++) {
                    GridTab tabuser = mTab.getGridWindow().getTab(i);
                    if (tabuser.getAD_Table_ID() == MUser.Table_ID) {
                        tabuser.setValue(MUser.COLUMNNAME_Name, value);
                        break;
                    }
                }
            }
        }
        return null;

Regards,

Carlos Ruiz

Stanislav Karakhanov

unread,
Nov 22, 2014, 3:45:21 PM11/22/14
to idem...@googlegroups.com
Thank you very much, Carlos!
It works!!!


суббота, 22 ноября 2014 г., 20:37:57 UTC+3 пользователь Carlos Antonio Ruiz Gómez написал:
Reply all
Reply to author
Forward
0 new messages