script to check if customer has record in repetitive invoice entry

Hi...

I am trying to create a small message script that if I change a particular field in a customer maintenance task, a message will pop up that the customer does not have a record in the A/R repetitive invoice file and it cannot be changed.

As it is, it will fire on every customer even if there is not a corresponding customer in repetitive invoice entry.

Here is what I have so far:

repinv = ""

cust = ""

custmain = ""

retVal= oBusObj.GetValue("CustomerNo$", cust)

retVal= oBusObj.GetValue("ReferenceNo",repinv)

retVal= oBusObj.GetValue("CustomerNo$",custmain)

if  cust <> custmain then

retStrVal = oSession.AsObject(oSession.UI).MessageBox("No entry allowed.")

end if

The record cust is the customer from the repetitive invoice file, the custmain is the customer from the customer maintenance file.

So, for instance customer JELLCO does not have a repetitive invoice in the file.  But I want the customer maintenance field I am changing on JELLCO to say "No entry allowed", but it does not.  I know the script is firing, if I change the cust = custmain , but it will always show the message.  So, I am pretty sure it is not retrieving the repetitive invoice customer number.

Thank you so much for any help.

B

  • 0
    Where exactly do you have this script?
    oBusObj refers to the current business object, that cannot be both AR_Customer and AR_RepetitiveInvoiceHeader at the same time.
    You will have to open a second one to refer to the second object.
  • 0 in reply to 49153
    I knew something is not right...thank you...I have the script on the customer maintenance screen, using a field on that screen to fire...Can you point me in the right direction to create the second object...not really sure what I am doing.
    Thank you so much...

    B
  • 0 in reply to beavis
    Something like this:

    ARDivisionNo = ""
    CustomerNo = ""

    retVal = oBusObj.GetValue("ARDivisionNo", ARDivisionNo)
    retVal = oBusObj.GetValue("CustomerNo", CustomerNo)

    'Create second object
    Set oARRepInv = oSession.AsObject(oSession.GetObject("AR_RepetitiveInvoice_bus"))

    'Set key values
    retVal = oARRepInv.SetKeyValue("ARDivisionNo$", ARDivisionNo)
    retVal = oARRepInv.SetKeyValue("CustomerNo$", CustomerNo)
    retVal = oARRepInv.SetKeyValue("ReferenceNo$", "REF") ' *** Add your Reference here ***

    r = oARRepInv.SetKey
    'SetKey returns:
    '1 = exists
    '2 = new record

    retVal = oSession.AsObject(oSession.UI).MessageBox(cstr(r))

    if r = 1 then
    retVal = oSession.AsObject(oSession.UI).MessageBox("Exists")
    elseif r = 2 then
    retVal = oSession.AsObject(oSession.UI).MessageBox("Does Not Exist")
    else
    retVal = oSession.AsObject(oSession.UI).MessageBox(cstr(r))
    end if

    Set oARRepInv = Nothing
  • 0 in reply to 49153
    Thank you my friend...but it doesn't seem to work the way I need it...it appears if the field changes on the customer maintenance, the message changes...what is supposed to happen is if someone changes the terms code field on the customer maintenance and there is no corresponding customer in the repetitive invoice file, then the system should show a message that this field cannot be changed...I think I just need the customer number record...keep helping me please...I appreciate it...thx..B
  • 0 in reply to beavis
    Oh...I got it now...I had to set all the key values..so I got it to work using one reference number, but I need to show multiple reference numbers...how to show three different references using the setkeyvalue...thanks...appreciate it...B
  • 0 in reply to beavis
    One at a time, or use an ADO query.
  • 0 in reply to 49153
    Thanks for the response...I added the record, but it will only show the last record I do...how do I add the record so it will do both?...I show :
    retVal = oARRepInv.SetKeyValue("ARDivisionNo$", ARDivisionNo)
    retVal = oARRepInv.SetKeyValue("CustomerNo$", CustomerNo)
    retVal = oARRepInv.SetKeyValue("ReferenceNo$", "0001")

    retVal = oARRepInv.SetKeyValue("ARDivisionNo$", ARDivisionNo)
    retVal = oARRepInv.SetKeyValue("CustomerNo$", CustomerNo)
    retVal = oARRepInv.SetKeyValue("ReferenceNo$", "0030")

    thanks for any help...it is making me crazy...B
  • 0 in reply to beavis
    You can only show one record at a time.
    What are you trying to achieve?
  • 0 in reply to 49153
    I want the message to appear if the repetitive invoice file shows either 0001 or 0030 as the reference number...how can I show the message on both references number/...I am so close....thanks ...B
  • 0 in reply to beavis
    Check if 0001 exists and set a variable = true, check if 0030 exists and set a variable = true.
    Now check the variables and set your message.