Not having an active key?

navnoob
navnoob Member Posts: 26
Hi all,

I have a project where I do
SalesInvHeader.RESET;
SalesInvHeader.SETCURRENTKEY("Sell-to Customer No.", "Posting Date");

inside a function inside my customer table.

When I run the customer card, it keeps telling me that

"The sales invoice header table does not have an active key that starts with the following field: Sell-to Customer No., Posting Date"

so my card cannot be run, so I thought maybe i have to add those fields to the keys inside the Sales Header Table, but still it keeps giving that message and my card not run. When i Remove the SETCURRENTKEY, then the card runs but not the result I want...

What mistake am I making?

Thank you.

                

Answers

  • kriki
    kriki Member, Moderator Posts: 9,132
    Are you sure that "SalesInvHeader" is a record on table 36:"Sales Header"?
    It seems to me it is a record on table 112:"Sales Invoice Header".

    And indeed, without SETCURRENTKEY it will work, but it will be slow. (On SQL, it might work fast anyway)
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • DenSter
    DenSter Member Posts: 8,307
    so:
    The table that you refer to with your SalesInvHeader variable must have an active key that has the "Sell-to Customer No.", "Posting Date" in it. I don't believe that it matters in which order, but both fields must be in the key.
  • kriki
    kriki Member, Moderator Posts: 9,132
    DenSter wrote:
    so:
    The table that you refer to with your SalesInvHeader variable must have an active key that has the "Sell-to Customer No.", "Posting Date" in it. I don't believe that it matters in which order, but both fields must be in the key.
    It does matter!
    Putting a date as first field is in general not a good idea for performance.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • navnoob
    navnoob Member Posts: 26
    gentlemen, so I took kriki advice and make sure the record variable is Sales header (36) and it is.

    So i don't get it. the field sell-to customer no. and posting date does exists in the sales header (36) table and why I cannot use setcurrentkey on those field?

    as I said before, I did try adding them to the key coulmns but it still doesn't work.

    Any other suggestion or help please?

    Thanks.
  • Savatage
    Savatage Member Posts: 7,142
    Just to clarify
    navnoob wrote:
    so I thought maybe i have to add those fields to the keys inside the Sales Header Table
    Is this still done? Did you add a new key or add a field to one?
    navnoob wrote:
    SalesInvHeader.RESET;
    SalesInvHeader.SETCURRENTKEY("Sell-to Customer No.", "Posting Date");
    
    And you’re sure SalesInvHeader (Name) is with Datatype (Record) is using Subtype (Sales Header)

    PS - Can you tell us what you are trying to evntually accomplish with this task?
  • kriki
    kriki Member, Moderator Posts: 9,132
    If the key exists. Is is also enabled?
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • navnoob
    navnoob Member Posts: 26
    Hi guys,

    sorry, but it was a dumb dumb mistake, i reput the key in the sales invoice header table and it work. I remember doing it yesterday but i guess i was so stress out i might be wrong.

    sorry for the trouble, but i thank you guys for the help.

    so problem is solved

    thanks thanks.
  • DenSter
    DenSter Member Posts: 8,307
    kriki wrote:
    DenSter wrote:
    so:
    The table that you refer to with your SalesInvHeader variable must have an active key that has the "Sell-to Customer No.", "Posting Date" in it. I don't believe that it matters in which order, but both fields must be in the key.
    It does matter!
    Putting a date as first field is in general not a good idea for performance.
    Didn't say it is good for performance, just that it doesn't matter for the error message to come up as long as the two fields are both in an active key. :mrgreen: