Page 1 of 1

Field Name Required

Posted: Sun May 08, 2016 6:56 am
by JeffG
Morning, I would like to write a script for r-csp.mac whereby at order entry or invoice data input, a message is displayed if the customer has a discount formula in their profile.

Only issue is, I can't find the account code field name to read.

Find(UPPER(SCRREAD("XXX"))) - what should XXX be ?

Thanks

Posted: Mon May 09, 2016 11:20 am
by COBS Tech Support
SCR*** functions only work within master screen areas. Such as when you have customer or stock screen open. You cannot use SCRRead() inside a script hook such as R-CSP.MAC as it may be called from outside those areas.

If you want to base a customer price rule on specific accounts you can access the field name by retrieving it from the database, i.e., Custrec->Cuscode.

Posted: Tue May 10, 2016 9:29 am
by JeffG
Thanks for that. However, I am not looking to set up any special pricing rules on a per customer basis, I can do that without a problem.

As I stated earlier what I need to do is have a message pop up at order entry time, either in a sales order or invoice, that warns my staff that if a discount formula is already present in Custrec->Cusform and that no further discount is to be applied.

Thanks

Posted: Tue May 10, 2016 9:33 am
by COBS Tech Support
That's not what you stated as all, as you referred to R-CSP.MAC which now has nothing to do with what you are writing about. You can use a transaction event hook and call ReadTranValue() to query the account code. Or, as already explained, simply refer to the database field, i.e. Custrec->XXX where XXX is the field you wish to query.

Posted: Tue May 10, 2016 9:37 am
by COBS Tech Support
Also will add, refer to the help topic Scripting Hooks, and then section Invoicing & Transactions. Hook of interest to you is likely Transaction Account Change Hook if your version of the software has it.

Another simple not script way to do this, would be to put a note against the account and have the system present the note, when an account is selected for a transaction.

Posted: Tue May 10, 2016 2:42 pm
by JeffG
Perfecto! Works like a treat. Hopefully now we wont be giving discounts on top of discounts.

For Future reference, and anybody else suffering the same fate, the following code was placed in both the R-ORACHG.MAC and R-INACHG.MAC files

Code: Select all

* Find if Customer already has a global discount

Declare cAccount Type String
Declare CusCode Type String
cAccount := ReadTranValue("Account")
Cuscode := cAccount

OpenTable("Custrec")
Custrec->(Find(Upper(cuscode)))

If IsEmpty(Custrec->CusForm)
   Return TRUE
Else
   nCusForm:= Custrec->Cusform
   Echo("This Customer already has a global discount!" + CHR(13) + "No More Discount!")
EndIf

CloseTable("Custrec")


Thanks

Posted: Wed May 11, 2016 1:18 pm
by COBS Tech Support
Suggestion: Better not to give your variable names the same names as field names in the database, as in some contexts the language system may choose a different value from what you expect. I.e., define cCusCode rather than Cuscode and so on.

Posted: Thu May 12, 2016 4:52 pm
by JeffG
I have the suggested changes. Thanks.

Question, though,

This is the current script

* Find if Customer already has a global discount

Declare cAccount Type String
Declare nCusCode Type String
Declare nCusForm Type String
cAccount := ReadTranValue("Account")
nCuscode := cAccount

OpenTable("Custrec")
Custrec->(Find(Upper(ncuscode)))
If IsEmpty(Custrec->CusForm)
Return TRUE
Else nCusForm:= scrread("Custrec->Cusform")
Echo("This Customer already has a global discount!" + CHR(13) + nCusForm + CHR(13) + "No More Discount")
nCusForm := ""
EndIf
CloseTable("Custrec")


in the message box, why would the "nCusForm" only show sometimes? I would have thought that variable was reset and read every time the table was opened.

Cheers

Posted: Mon Jan 30, 2017 12:07 pm
by COBS Tech Support

Code: Select all

If IsEmpty(Custrec->CusForm) 
Return TRUE
Else nCusForm:= scrread("Custrec->Cusform")
Echo("This Customer already has a global discount!" + CHR(13) + nCusForm + CHR(13) + "No More Discount")
nCusForm := ""
EndIf


The above syntax is not valid but this syntax is:

Code: Select all

If IsEmpty(Custrec->CusForm) 
   Return TRUE
Else
   nCusForm:= scrread("Custrec->Cusform")
   Echo("This Customer already has a global discount!" + CHR(13) + nCusForm + CHR(13) + "No More Discount")
   nCusForm := ""
EndIf