New customer field initialization

SOLVED

Hi All

When I am creating a new customer, depending on custdiv, I need to initialize certain field, like custtype, pricelevel, etc. What kind of event would I use? Column event does not have CustDiv. In post-write or pr-write event it did not work.

Any help will be highly appreciated.

  • 0
    Have you tried the event Table-Set Default Values?
  • 0 in reply to TomTarget
    I tried that but did not work. I also tried Script Initialization event. I made sure that I used oBusObj.write() method.
    Any other suggestions are welcome.
    Thanks.
  • 0 in reply to ADongre
    Try a post validate on something the user will always set, like customer name. Restrict the script on EditState (...whatever the value is for a new record) so you don't rerun the script for edits.
  • 0 in reply to ADongre
    Can you provide the symptom you encountered with you tried Table-Set Default values? The phrase "did not work" doesn't give any information. For example, did you get an error message? Did you get a unsuccessful return from the key methods? Did your code not run at all? Did you use Debug.Print statements that verified your variables used to store into fields?
  • 0 in reply to connex
    Hi Kevin
    I tried post-validate on CustomerName but did not work. Afrer accepting the record and opened it again and no field were populated. When I start new record it shows as "New" but in my script it does not recognize it as such. I have if statement saying If oBusObj.Efitstate = 2 etc
    and if it is true then I display a message saying I am in, which I did not see, meaning next statements did not execute.
    Any ideas are welcome.
    Thanks
  • 0 in reply to ADongre
    Hi Connex
    See my reply to Kevin. It did not work meaning no fields were populated. There wer no error message. I suspect the script did not recognize oBusObj.EditState = 2.
    Thanks
  • 0 in reply to ADongre
    In testing triggers, I often just script a pop-up to make sure it is firing.
  • 0 in reply to Kevin M
    verified answer

    ADongre , are you trying to set these fields to a value that will be used for all new customers or will the value change based on another field value?

    If it is always going to be the same value for all new customers, you should be able to accomplish this with the Table Default Values that TomTarget mentioned.

    Go to "Custom Office" > "Main" > "User-Defined Field and Table Maintenance".

    Navigate to the table, in your case "Accounts Receivable" > "AR Customer Master".

    Right click the table and choose "Advanced Field Settings..."

    Click the green plus sign button.

    Select your field from the drop down.

    Key in the Default Value.

    Click OK.

    Now, if you are committed to using a script to set these values on a new customer then you could use the table post read event, it should trigger even for new records. Then in your script make sure oBusObj.EditState equals 2 indicating a new record.

    If your values may change depending on another field, then you should use a post validate event script on the field you are basing your value off of.

  • 0 in reply to David Speck
    SUGGESTED
    Hi David'
    The values are dependent on AR_CustomerDivision.
    I have resolved this issue. I was making a mistake of using Write() when I am still in BusObj
    Thanks for your help