I have created an updatable BAQ for our Supply/Chain team which includes a dozen or so updatable fields in Part, PartPlant and PartWhse. This was then applied to a dashboard so it could be placed on the menu. During testing I noted that if any one of the dozen updatable fields has an error, the entire row turns red. I also found that a tooltip is used to state the error, but this only applies to the first one it encounters. To get around this, I created a UBAQ Method Directive for Update (Pre-processing) which has this code:
string pubMsg = "";
var resultQuery = queryResultDataset.Results
.Where(row => !string.IsNullOrEmpty(row.RowMod)
&& row.RowMod != "P");
foreach (var ttResult in resultQuery)
{
var buyerChk = (from buyerRow in Db.PurAgent
where buyerRow.BuyerID == ttResult.PartPlant_BuyerID
select buyerRow).FirstOrDefault();
if (buyerChk == null && buyerChk.BuyerID != "")
{
pubMsg += "Invalid Buyer specified for Part " + ttResult.Part_PartNum + ".\r\n";
}
var planChk = (from planRow in Db.Person
where planRow.PersonID == ttResult.PartPlant_PersonID
select planRow).FirstOrDefault();
if (planChk == null && planChk.PersonID != "")
{
pubMsg += "Invalid Planner specified for Part " + ttResult.Part_PartNum + ".\r\n";
}
var abcChk = (from abcRow in Db.ABCCode
where abcRow.ABCCode1 == ttResult.PartWhse_SystemAbc
select abcRow).FirstOrDefault();
if (abcChk == null && abcChk.ABCCode1 != "")
{
pubMsg += "Invalid ABC Code specified for Part " + ttResult.Part_PartNum + ".\r\n";
}
}
if(pubMsg != "")
{
this.PublishInfoMessage(pubMsg,Ice.Common.BusinessObjectMessageType.Warning,0,"","");
}
My problem is that updates do not occur when this method directive is enabled. Disabling the method directive allows updates to occur.
I usually put this kind code check post processing on getlist and put a comment into a calculated field with what is wrong so they know in advance and don’t try to update and in the update processing check that status is blank before processing.
I really wanted to use FieldValidate. According to the Ice Tools User Guide:
This method occurs before the proposed change to a field is committed. You can use this method to validate proposed changes. For example, you can prevent users from entering an incorrect value in a certain field such as non-existent state.
Unfortunately, my initial attempts failed to produce any result. In a perfect world, this would fire once the user hits tab, but I couldn’t even get a simple message to display.
Well, it looks like I got my “perfect world” solution, and it works great. Here’s what I did…
In the BAQ Designer, I went to Update > General Properties and clicked the “Advanced Column Editor Configuration” button at the bottom. For each field that I wanted to FieldValidate to know about, I checked “Raise Events”.
Once this was done, I went back to the Updatable BAQ Method Directive, and created a new BPM for FieldValidate with the following code:
string fieldDesc = "";
if(result == false)
{
switch(fieldName)
{
case "PartPlant_BuyerID":
fieldDesc = "Buyer";
break;
case "PartPlant_PersonID":
fieldDesc = "Planner";
break;
case "PartWhse_SystemAbc":
fieldDesc = "ABC Code";
break;
}
if(fieldDesc != "")
{
throw new BLException("Invalid " + fieldDesc + ". Please re-enter or use the drop-down to select an option.");
}
}
Now, whenever a user types an invalid value and hits TAB, they get a simple exception message, and the cursor remains in the field with the bad value, and the row does not turn red.
Fortunately, in my case I was able to create mini-BAQs for the Updatable Field Editor to use for the drop-down values and their descriptions. My Supply/Chain director even made me create one for ABC Code since they might someday create a fourth option.