Sorting by Flowfield - on demand/timer, frm already filtered

shogan@mila.ieshogan@mila.ie Member Posts: 113
Hi all,

I have a form based on the Sales Order List, that has a filter applied to the Credit Status field. It refreshed using OnTimer every 10 seconds.

What I would like to do is sort it by Credit Status, however it is a flowfield.

I am wondering if anyone would object to the following way I am doing things:

On the Sales Header table, I have a new Credit Status - Sort field created.

On the form itself:
Form - OnAfterGetRecord()

CALCFIELDS("Credit Status");
"Credit Status - Sort":= FORMAT("Credit Status");

As the form can be sorted with custom buttons, I have applied a new "Sort by Credit Status" button, with the following code:
btnSortCrStatus - OnPush()

SETCURRENTKEY("Document Type","Credit Status - Sort","No.");

Credit Status is an option field, however Credit Status - Sort is a text field.


I only need to apply the sort on the records currently filtered when opening/refreshing the form, and not the entire Sales Header table.

I have been looking at code where people wanted to sort by Customer Balance or Sales (LCY) and there was mention of outputting to a different table, or updating a field on the current table, with REPEAT, RESET, FIND('-'), and letting a new field equal the old one. Also, there was talk of looking at the Top 10 reports.

I think I have it simplified somewhat in my approach above; just wondering if I should/need to lock the Sales Header table, despite the fact that it is an inexpensive task.


Thoughts welcome.


Regards,
Stephen

Comments

  • tothszabolcstothszabolcs Member Posts: 21
    hi,

    it should work, because is u use a filter after that u change the sorting, than sorting applying for filtered records.

    Did you called MODIFY after this: "Credit Status - Sort":= FORMAT("Credit Status"); ?
  • shogan@mila.ieshogan@mila.ie Member Posts: 113
    Actually no, I didn't - let me test that (and thanks for the reply!)
  • shogan@mila.ieshogan@mila.ie Member Posts: 113
    So I cannot use MODIFY; within the OnAfterGetRecord() trigger:
    "You cannot make any changes in the database until a transaction has been started"

    So I have taken a different approach:

    The form will sort by order no. on opening.

    So I made the following function:
    fCreditStatusSort()
    // 2014-07-18 shogan@mila.ie ----- START
    // Function to assist sorting the form by 'Credit Status'.
    //   Writes value from 'Credit Status' flowfield to 'Credit Status - Sort' text field.
    
    IF FIND('-') THEN
       REPEAT
          CALCFIELDS("Credit Status");
          "Credit Status - Sort":= FORMAT("Credit Status");
          MODIFY;
       UNTIL NEXT = 0;
    
    // 2014-07-18 shogan@mila.ie ----- END
    


    I call this from my Timer function and a dedicated button.

    I hope this helps people out!

    Interesting discovering this!
Sign In or Register to comment.