1. William Beale
  2. PowerBuilder
  3. Sunday, 28 February 2021 05:59 AM UTC

I’m trying to trap an item error event message to enable a user to enter a new text value to a code-based drop down datawindow. 

The DDDW is set to allow editing. ‘Empty String is NULL’ is checked. Is not set as a ‘required’ column. The DB is MS SQL Server but the column in question cannot be set to NULL because it composes the primary key.

Text values and corresponding numeric code for the DDDW are stored in a lookup table. 

If a User enters a text value that is not in the table,  in the item error event, I want to trap the error and send a message the effect, “Your entry, ‘xxxxx’, does not exist in the lookup table.  Do you want to add  ‘xxxxx’ to this table?’

I then have a function that adds the new text value and corresponding numeric code to the table, and refreshes the DDDW with the intent to allow the User to proceed.  In doing this, my intention is to  hopefully bypass the item error event.

However, when I attempt, via code in the item error event, to get the invalid text value from the entry in the DDDW to send to the function, I get a message, ‘Item ‘xxxx’ does not pass the validation test’

I’ve done a global search of the entire pbl set to find elements of this message, ie a search on ‘does not pass the validation test’.  

I’ve also searched on PB validation code but come up empty.

Stepping through on debug hasn’t helped either in attempting to locate the source of this message.

Because I can’t locate the source of this message, or bypass it, I wonder whether it is hardcoded and thus inaccessible in the datawindow object (I use u_dw from a 1997 pfc pbl). 

I appreciate I can devise stand-alone ways and have the User side-tracked to add to the DDDW but I’d like to make it simple and allow them to do it on the fly.

Any suggestions how I can bypass this validation message or is there another strategy?

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Sunday, 28 February 2021 16:02 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi, William - 

It's not a trivial thing to accomplish. I suspect this is why you do not see many apps do what you are wanting to accomplish. 

Arthur is correct that the message is a default PB DW validation message. In your case, you have a data column that uses the DDDW edit style, the user enters a string value that PB cannot locate in the child DW, and since there is no handling of the validation error in either ItemChanged or ItemError events, you get the default message. Your code will need to recognize and handle this set of conditions.

There are many ways to approach this, I suppose. I've used the PFC for 20+ years, and while I have not done exactly what you are describing, here's how I would try to accomplish it:

1. Perform this data validation check in the ItemChanged event. Here is where I think you'll need to explicitly perform the same validation steps that PB does by default... Do a GetChild and perform a Find in the child DW to try and locate the user's data value. If it is there, issue a return code of zero (accept the data value) and proceed normally.

2. If the data value is not present in the child DW, then here is where you prompt the user about adding the new value to your secondary/code table. Issue return code 1 (reject the value and do not allow focus to change) if the user does NOT wish to add the new entry. If the user agrees, however, you can issue the InsertRow and Update methods on the DataWindowChild, then if the Update is successful, issue a return code of zero in the ItemChanged event to prevent PB from issuing its default validation message.

It's important that the child DW itself contains the newly-added value in order to prevent the same action from repeating itself if the user enters the same (new) string value in the same DataWindow Control. Also consider what to do if the same data column and DDDW is used by another DW in a window that is already open or if another instance of the same window is open... you'll also want to try and re-retrieve those DataWindowChild objects so they pick up the newly-added row. Like I said at the beginning of this diatribe - It's not a trivial task. But, it would be a nice feature... I'm just not convinced it's worth the development effort, but that's your call.

Good luck!

Regards, John

 

Comment
  1. William Beale
  2. Sunday, 28 February 2021 22:34 PM UTC
Thanks John for your detailed advice. Appreciated.
  1. Helpful
There are no comments made yet.
Arthur Hefti Accepted Answer Pending Moderation
  1. Sunday, 28 February 2021 08:25 AM UTC
  2. PowerBuilder
  3. # 1

Hi 

base on your description it's a bit difficult answer. We have something similar but adding is done without asking the user.

- The "Item does not pass validation test" is a default DataWindow error message
- You can define how PB handles the error in the itemerror event by it's return value
- I don't know how you want to get the text in the itemerror event, another AcceptText()?, it's passed in the "data" argument of the itemerror event.

Regards
Arthur 

Comment
  1. William Beale
  2. Sunday, 28 February 2021 22:35 PM UTC
Thanks Arthur. You've confirmed my thoughts on the validation message. I'll check out the passing of the data argument - that could help.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.