Hello,
I am working on a scripting solution that sets a hard cap on the number of free sample items a salesperson can receive. I currently have a UDT set up that tracks how many of each product line a sales person has, and am able to write to that table fine. However, I want to be able to set the price to 0 if they have not reached the limit, but keep the price at the normal price if they have reached the limit. My two current problems are the following:
1) It appears that to change the price, I need to have the price change to be on a script that is not of the Post-Table-Write type. However, doing so causes the item quantities to be written to my UDT even when the user cancels the order. If anyone knows a simple solution to this problem I would be very grateful.
2) If the cap for the product line "Rugs" is 10, and the salespersons current quantity is at 5, they are allowed to purchase as many different rugs as they want as long as each specific rug has quantity less than 5. I would like to be able to update the current quantity on the UDT as the order is placed, but for changes to be disregarded if the order is cancelled.
The below script currently works great for recording the number of free samples that have been used, but is incomplete as I'm not sure where to go from here (One script, multiple scripts, etc), and I have included it to give you all an idea of where I'm at:
This is currently set up as Post Table Write:
'Sales Person Free Sample Cap
'Initialize Variables
SP = ""
ItemC = ""
pLine = ""
Qty = 0
QtyOld = 0
price = 0
cap = 0
BSWA = 0
CORN = 75
PILL = 35
THRO = 5
VAS = 3
LIG = 3
WALL = 1
'Grab Data
retVal = oHeaderObj.GetValue("SalesPersonNo$", SP)
retVal = oBusObj.GetValue("ItemCode$", ItemC)
retVal = oBusObj.GetValue("QuantityOrdered", Qty)
retVal = oBusObj.GetValue("UnitPrice", price)
set oCap = oSession.AsObject(oSession.GetObject("CM_UDTMaint_bus", "SO_UDT_Cap"))
set oItem = oSession.AsObject(oSession.GetObject("CI_ItemCode_bus"))
retVal = oItem.GetValue("ProductLine$", pLine)
'Write to Table
resul = oCap.SetKey(SP + pLine)
If resul = 2 then
result = oCap.SetValue("UDF_Current", Qty)
result = oCap.SetValue("UDF_SALESPERSON$", SP)
result = oCap.Write()
End If
If resul = 1 Then
result = oCap.GetValue("UDF_Current", QtyOld)
result = oCap.SetValue("UDF_Current", QtyOld + Qty)
result = oCap.Write()
End If
Any guidance in this will be greatly appreciated!