Field Name Required
  • JeffG
    Posts:91
    Joined:Sat Aug 31, 2013 6:50 pm
    Location:Sydney
    Field Name Required

    by JeffG » Sun May 08, 2016 6:56 am

    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
  • COBS Tech Support
    Posts:683
    Joined:Fri Sep 09, 2005 8:23 am

    by COBS Tech Support » Mon May 09, 2016 11:20 am

    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.
  • JeffG
    Posts:91
    Joined:Sat Aug 31, 2013 6:50 pm
    Location:Sydney

    by JeffG » Tue May 10, 2016 9:29 am

    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
  • COBS Tech Support
    Posts:683
    Joined:Fri Sep 09, 2005 8:23 am

    by COBS Tech Support » Tue May 10, 2016 9:33 am

    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.
  • COBS Tech Support
    Posts:683
    Joined:Fri Sep 09, 2005 8:23 am

    by COBS Tech Support » Tue May 10, 2016 9:37 am

    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.
  • JeffG
    Posts:91
    Joined:Sat Aug 31, 2013 6:50 pm
    Location:Sydney

    by JeffG » Tue May 10, 2016 2:42 pm

    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
  • COBS Tech Support
    Posts:683
    Joined:Fri Sep 09, 2005 8:23 am

    by COBS Tech Support » Wed May 11, 2016 1:18 pm

    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.
  • JeffG
    Posts:91
    Joined:Sat Aug 31, 2013 6:50 pm
    Location:Sydney

    by JeffG » Thu May 12, 2016 4:52 pm

    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
  • COBS Tech Support
    Posts:683
    Joined:Fri Sep 09, 2005 8:23 am

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

    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

Who is online

Users browsing this forum: No registered users and 6 guests