Sales Order - Blanket Sales Order problem

sarabi98sarabi98 Member Posts: 13
I have implemented the following:
Added a new fields on the sales order header call Max Amount and Max Amount Threshold.
The problem I am having is the user should get a warning if the blanker order lines exceed the Max amount. and Alse the user gets a warning when billing more that the Max Amount * Max Amount Threshold.
How can I do this with code?
I have created a function and has the below code:

Is this on the right track? Am i missing something?
Totalfields is a variable in the function.
SalesLine.SETRANGE("Document Type","Document Type");
SalesLine.SETRANGE("Document No.","No.");
//SalesLine.TotalFields(SalesLine.Amount);
TotalFields := TotalFields + SalesLine.Amount;
IF("Max Amount" * "Max Amount Threshold") > SalesLine.Amount THEN
  MESSAGE(Text052, "Max Amount",SalesLine.Amount);

Comments

  • Ravi_Prakash_GoyalRavi_Prakash_Goyal Member Posts: 72
    Code should be like this:

    SalesLine.SETRANGE("Document Type","Document Type");
    SalesLine.SETRANGE("Document No.","No.");
    //SalesLine.TotalFields(SalesLine.Amount);
    if SalesLine.FIND('-') THEN repeat
    TotalFields := TotalFields + SalesLine.Amount;
    until SalesLine.next = 0;

    IF TotalFields > ("Max Amount") THEN
    MESSAGE('Amount cannot be more than %1', "MaxAmount");

    //IF("Max Amount" * "Max Amount Threshold") > SalesLine.Amount THEN
    // MESSAGE(Text052, "Max Amount",SalesLine.Amount
  • David_CoxDavid_Cox Member Posts: 509
    sarabi98 wrote:
    I have implemented the following:
    Added a new fields on the sales order header call Max Amount and Max Amount Threshold.
    The problem I am having is the user should get a warning if the blanker order lines exceed the Max amount. and Alse the user gets a warning when billing more that the Max Amount * Max Amount Threshold.
    How can I do this with code?
    I have created a function and has the below code:

    Is this on the right track? Am i missing something?
    Totalfields is a variable in the function.
    SalesLine.SETRANGE("Document Type","Document Type");
    SalesLine.SETRANGE("Document No.","No.");
    //SalesLine.TotalFields(SalesLine.Amount);
    TotalFields := TotalFields + SalesLine.Amount;
    IF("Max Amount" * "Max Amount Threshold") > SalesLine.Amount THEN
      MESSAGE(Text052, "Max Amount",SalesLine.Amount);
    

    IF("Max Amount") > SalesLine.Amount THEN
    MESSAGE(Text052, "Max Amount",SalesLine.Amount);

    IF("Max Amount" * "Max Amount Threshold") > TotalFields THEN
    MESSAGE(Text052, "Max Amount" *"Max Amount Threshold",TotalFields);
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Ravi_Prakash_GoyalRavi_Prakash_Goyal Member Posts: 72
    Code should be like this:

    SalesLine.SETRANGE("Document Type","Document Type");
    SalesLine.SETRANGE("Document No.","No.");
    if SalesLine.FIND('-') THEN repeat
    IF SalesLine.Amount > ("Max Amount") THEN
    MESSAGE('Amount cannot be more than %1 in Line No.
    %2', "MaxAmount",SalesLine."Line No.");
    TotalFields := TotalFields + SalesLine.Amount;
    until SalesLine.next = 0;

    IF TotalFields > ("Max Amount" * "Max Amount Threshold") THEN
    MESSAGE('Total billing Amount cannot be more than %1',
    "Max Amount" * "Max Amount Threshold");
  • sarabi98sarabi98 Member Posts: 13
    Thank you for the help. I was able to make it work, and changed the code around. However, I still need to be able to check if in the Subform for Sales Line table, the Line Amount Field does not become greater than my max amount. I am calling the function in the Sales Line table under the line Amount field as follows (onvalidate() for line amount)
    SalesHeader.CheckThresholdValue(TotalLineAmount2,MaxThresholdValue2);
    

    For CheckThresholdValue function, the Parameters are set to pass by reference.
    //This is the function code
    SalesLine.SETRANGE("Document Type","Document Type"); 
    SalesLine.SETRANGE("Document No.","No."); 
    
    IF SalesLine.FIND('-') THEN REPEAT
      TotalAmount := TotalAmount + SalesLine."Line Amount";
    UNTIL SalesLine.NEXT = 0;
    
    Threshold := ("Max Amount" * ("Max Amount Threshold"/100));
    
    IF("Max Amount") < TotalAmount THEN
      MESSAGE(Text053, TotalAmount,"Max Amount")
    ELSE 
      IF(Threshold) < TotalAmount THEN
      MESSAGE(Text052, TotalAmount,Threshold);
    

    Am I calling the function in the correct place for line amount in the sales line table? Where should i call the function from?
Sign In or Register to comment.