get empty mandatory fields from a process

Help is preferred to those who publish their work as Open Source and not as private branches rejecting collaboration. Such projects are not maintainable and shall be deleted.
Forum rules
This forum is personally pruned to avoid redundant posts. Related topics are grouped together. IF YOU HAVE REGISTERED, you need to send email to red1(a)red1.org with your username in the subject title to get me to activate you.

get empty mandatory fields from a process

Postby nmicoud » Tue Oct 23, 2012 11:42 pm

Hi,

Do you think it is possible to get a list of mandatory empty fields from a window (and for a specific record) and show at the end of a process ?

Something like in GridTable :

Code: Select all
//   Check Mandatory
String missingColumns = getMandatory(rowData);
if (missingColumns.length() != 0)
{
  //   Trace.printStack(false, false);
  fireDataStatusEEvent("FillMandatory", missingColumns + "\n", true);
  return SAVE_MANDATORY;
}


Process param would be : Record_ID and window_id would be hardcoded.

Thanks,

Nicolas
nmicoud
Regular
 
Posts: 137
Joined: Fri Oct 07, 2011 6:19 pm

Re: get empty mandatory fields from a process

Postby red1 » Sun Nov 18, 2012 7:18 pm

Isn't this bit straightforward counting routine? If you are already using a process class, then i reckon you be putting such a clause there to traverse the table-columns for the mandatory ones that have nulls and count them for you.
red1
Site Admin
 
Posts: 2759
Joined: Tue Jul 06, 2004 3:01 pm
Location: Kuala Lumpur, Malaysia

Re: get empty mandatory fields from a process

Postby nmicoud » Mon Nov 19, 2012 4:55 pm

I finally managed to do it by selecting every fields of my window and test them using Evaluator.
Only checking mandatory was not enough because some fields are required only if another field has a specific value (written in MandatoryLogic).

So, i test those fields and can proceed if everything is ok ; otherwise, i say "this field (XXX) is not filled".

Nicolas
nmicoud
Regular
 
Posts: 137
Joined: Fri Oct 07, 2011 6:19 pm

Re: get empty mandatory fields from a process

Postby red1 » Tue Nov 20, 2012 6:16 pm

Oh i see, i wonder if you can show some step by step screenshots on how you do it, or refresh me what is this Evaluator.
red1
Site Admin
 
Posts: 2759
Joined: Tue Jul 06, 2004 3:01 pm
Location: Kuala Lumpur, Malaysia

Re: get empty mandatory fields from a process

Postby nmicoud » Tue Nov 20, 2012 7:20 pm

Evaluator is used to determine if a field (or tab) should be displayed or hidden.

I'm using it to see if, in the context of my record, a field has to be filled.

Here's my code to get a list of mandatory column, according to a specific record :

Code: Select all
   static MColumn[] columnsMandatory(Properties ctx, PO po, int tableID, int recordID, String trxName)
   {
      ArrayList<MColumn> listColumns = new ArrayList<MColumn>();
      
      MDevice device = new MDevice(ctx, recordID, trxName);
      int windowID = 1000002; // TODO hardcoded

      // List of tabs based on po
      String sql = "SELECT t.AD_Tab_ID"
            + " FROM AD_Tab t"
            + " WHERE t.IsActive='Y' AND t.AD_Window_ID=" + windowID
            + " AND t.AD_Table_ID=" + po.get_Table_ID()
            + " ORDER BY t.SeqNo";

      PreparedStatement pstmt = null;
      ResultSet rs = null;
      try
      {
         pstmt = DB.prepareStatement (sql, trxName);
         rs = pstmt.executeQuery ();
         while (rs.next ())
         {
            int tabID = rs.getInt(1);
            MTab tab = new MTab(ctx, tabID, trxName);
            boolean needToCheckTab=false;

            if (tab.getDisplayLogic()==null)
               needToCheckTab=true;
            else
            {
               if (Evaluator.evaluateLogic(device, tab.getDisplayLogic()))
                  needToCheckTab=true;
            }

            if (needToCheckTab)
            {
               String sql2 = "SELECT f.AD_Field_ID"
                     + " FROM AD_Field f"
                     + " INNER JOIN AD_Tab t ON (f.AD_Tab_ID = t.AD_Tab_ID)"
                     + " WHERE f.IsDisplayed='Y' AND f.AD_Tab_ID="+tabID
                     + " ORDER BY t.SeqNo, f.IsDisplayed DESC, f.SeqNo";

               PreparedStatement pstmt2 = null;
               ResultSet rs2 = null;

               pstmt2 = DB.prepareStatement (sql2, trxName);
               rs2 = pstmt2.executeQuery ();
               while (rs2.next ())
               {
                  int fieldID = rs2.getInt(1);
                  MField field = new MField(ctx, fieldID, trxName);
                  MColumn column = new MColumn(ctx, field.getAD_Column_ID(), trxName);

                  if (column.getAD_Column_ID() == 1000557 || column.getAD_Column_ID()==1000559)
                     continue;
                  
                  System.out.println("=> " + column);

                  boolean checkValue = false;

                  if (field.getIsMandatory() != null && field.getIsMandatory().equals(X_AD_Field.ISMANDATORY_Yes) && field.getDisplayLogic()==null)
                     checkValue=true;
                  else if (field.getDisplayLogic()!=null && Evaluator.evaluateLogic(po, field.getDisplayLogic()))
                     checkValue=true;               
                  else // mandatory in base or have a mandatorylogic
                  {
                     if (column.isMandatory())
                        checkValue=true;
                     if (column.getMandatoryLogic() != null && Evaluator.evaluateLogic(po, column.getMandatoryLogic()))
                        checkValue=true;
                  }

                  if (checkValue)
                  {
                     listColumns.add (column);
                     System.out.println(" - " + column.getColumnName());
                  }
               }
            }
         }
      }
      catch (Exception e)
      {
         s_log.log(Level.SEVERE, sql, e);
      }
      finally
      {
         DB.close(rs, pstmt);
         rs = null; pstmt = null;
      }

      MColumn[] columns = new MColumn[listColumns.size ()];
      listColumns.toArray (columns);

      return columns;



Then, i can check if those columns are empty or not.
nmicoud
Regular
 
Posts: 137
Joined: Fri Oct 07, 2011 6:19 pm

Re: get empty mandatory fields from a process

Postby red1 » Thu Nov 29, 2012 7:38 am

This can be a good addition to org.compiere.model.po (Persistence Object class). Which gets me wondering - what if we collect such goodies as a plugin i.e. 'ExtraDevUtils"
red1
Site Admin
 
Posts: 2759
Joined: Tue Jul 06, 2004 3:01 pm
Location: Kuala Lumpur, Malaysia

Re: get empty mandatory fields from a process

Postby nmicoud » Thu Nov 29, 2012 3:52 pm

No problem if you want to add it, you're welcome !
nmicoud
Regular
 
Posts: 137
Joined: Fri Oct 07, 2011 6:19 pm


Return to HELP ME!!!

Who is online

Users browsing this forum: No registered users and 1 guest

cron