Orders!SOLines, formview, ItemNum:

nElementChange ... If an ItemNum that warrants a suggested alternative, I have a Writeln window notify user of that. My problem is that the Writeln is writing twice instead of just once, and I can't figure out where my error is. It triggers on vFlag = 0, and then I've got a vFlag = 2 just before the Writeln code, but it's looping back through and writing twice, even though the vflag shows as a 2 ... first the code (relevant lines in red), then the Writeln result (it's not a problem for the line to be duplicatd, by I want to learn what's not right in my code so I'll know better in other tasks)...
If @Group <> "clients"
{ //a
If ((@Mode() = 0) or (@Mode() = 1)) //and ((ItemNum) <> "AddRookie") // this code searches for a matching Inventory record and, if found, populating other fields
{ //b
If vFlag = 0
{ //c
If (((ItemNum) <> "AddRookie") and (@IsBlank(ItemNum) = 0) and (ItemNum <> "Stop") and (ItemNum <> "vStop"))
{ //d
SONum = @FORMFIELDVALUE("Orders","SONum",0) // this first section fills in SONum, SODate, ClientID
SODate = @FormFieldValue("Orders", "SODate", 0)
SOTime = @FormFieldValue("Orders", "SOTime", 0)
ClientName = @FormFieldValue("Orders", "ClientName", 0)
ClientID = @FORMFIELDVALUE("ORDERS","ClientID",0)
v2ItemNum = @FormFieldValue("SOLines", "ItemNum", 0)
vRS2 = @XResultSetSearch(@FN, "Inventory", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!ItemNum=" + v2ItemNum)
If @XresultSetTotal(vRS2) = 1 // if there is exactly one matching record in Inventory, pull data from Inventory into SOLines
{
// Get and then plug ItemDesc, Cost, UoM, Cat and issue message box to manually enter Price
v2ItemDesc = @XResultSetValue(vRS2, "ItemDesc")
v2ItemUom = @XResultSetValue(vRS2, "ItemUoM")
v2ItemCost = @XResultSetValue(vRS2, "ItemCurrentCost")
v2ItemCat = @XResultSetValue(vRS2, "ItemCat")
v2InternalNote = @XResultSetValue(vRS2, "InternalNote")
FormFieldValue("SOLines", "ItemDesc", 0, v2ItemDesc)
FormFieldValue("SOLines", "ItemUoM", 0, v2ItemUoM)
FormFieldValue("SOLines", "ItemCost", 0, v2ItemCost)
FormFieldValue("SOLines", "ItemCat", 0, v2ItemCat)
vQtyAvail = @XResultSetValue(vRS2, "QtyAvail")
vQtyOnOrder = @XResultSetValue(vRS2, "QtyOnOrder")
FormFieldValue("", "QtyAvail", 0, vQtyAvail)
FormFieldValue("", "QtyOnOrder", 0, vQtyOnOrder)
// the next section finds QtyOnBuild
v3ItemNum = v2ItemNum
vRS3 = @XResultSetSearch(@FN, "Purch!POLines", SEARCH_MODE_AND,SEARCH_SYNTAX_QA, "!ItemNum=" + v3ItemNum, "!PODate=" + @Date)
v3Tot = @XResultSetTotal(vRS3)
v3Date = @XResultSetValue(vRS3, "PODate")
v3POYN = @XResultSetValue(vRS3, "POLinesYN")
v3ItemQty = @XResultSetValue(vRS3, "ItemQty")
v3Loop = 0
For v3Loop = 1 to v3Tot
XResultSetCurrentPosition(vRS3, v3Loop)
v3POYN = @XResultSetValue(vRS3, "POLinesYN")
If v3POYN <> ""
{
XResultSetRemoveRecord(vRS3)
v3Loop = v3Loop - 1
v3Tot = v3Tot - 1
}
Next
v3Loop = 0
For v3Loop = 1 to v3Tot
XResultSetCurrentPosition(vRS3, v3Loop)
v3P = @XResultSetCurrentPosition(vRS3)
v3ItemQty = @XResultSetValue(vRS3, "ItemQty")
v3QtyOnBuildTotal += @TN(v3ItemQty)
Next
FormFieldValue("", "QtyOnBuild", 0, v3QtyOnBuildTotal)
XResultSetClose(vRS3)
Clear(ItemPrice)
RGBColor(AddThisLineItem, -1, -1, -1, 0, 255, 0)
If vFlag = 0 // a reminder popup for inventory items where alternatives should be suggested
{
vFlag = 1 If v2InternalNote <> "" {
vFlag = 2 Writeln(vFlag + " Pay attention to this note!!!! ... " + v2InternalNote) }
}
}
the result ....
2 Pay attention to this note!!!! ... Would the client like Xerox@ and save over 20% at the same time?
2 Pay attention to this note!!!! ... Would the client like Xerox@ and save over 20% at the same time?