SO in company A, look for Shipment in company B

j.marseloj.marselo Member Posts: 102
to experts,

i'm new in development in c/al, so i need help.

i hv 2 companies, BB is trading company and receiving order from end customer and give PO to company AA.
BB is a manufacturing site and shipping the prod.output to company BB.

in BB company, i need to add in certain empty area in Sales Order form about the status of order, by jumping to company AA and see if it's shipped or not.

the PO No. (table: purchase header) of company=BB is always transferred to External Document No. (table: sales header) of company=AA. External Document No. (table: sales header) in SO is always transferred to the same field in Sales Shipment Header.External Document No.

lineExtDoc, aassh, aaso, aapostdt, aacont are Global var.

the code:

lineExtDoc := "Purchase Order No.";
//i use breakpoint on this to make sure what "lineExtDoc" contains.

aassh.CHANGECOMPANY('AA');
aassh.SETFILTER("External Document No.",lineExtDoc);
aassh.CHANGECOMPANY('AA');
IF aassh.FIND('=') THEN BEGIN
aaso := aassh."Order No.";
aapostdt := aassh."Posting Date";
aacont := aassh."Package Tracking No.";
END ELSE BEGIN

//if now found (why it can not find???)
//I want to grab whats actually these var's contain

aaso := COMPANYNAME;
aapostdt := 0D;
aacont := aassh.GETFILTER("Order No.");
MESSAGE('The filter of aassh.Order No. :',aacont);
END;

when I open SO in company=BB, the text box of aaso, aapostdt and aacont are still not showing the related Shipment information. in fact, I check there's actually a shipment from company=AA to BB.

what's wrong in my code.

thank you.
Kind regards, Joe Marselo | see my NAV blog joemarselo.wordpress.com | twitter @joemarselo

Comments

  • DaveTDaveT Member Posts: 1,039
    Hi JM,

    There is two possibilities to solve your problem

    1. You are not testing the CHANGECOMPANY command for success (which is case sensitive)

    2. you are using a FIND('=') which finds on the primary key which you are not setting. I would suggest a FIND('-') instead.

    Hope this helps
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • j.marseloj.marselo Member Posts: 102
    the CHANGECOMPANY command is no problem.

    the problem lies on the returned record on: aassh.SETFILTER("External Document No.",lineExtDoc);
    the results are more than 1 lines. #-o

    next thing is FIND ; i think i have ranged the records to follow my criteria on filters command in lines above.
    but seems, the FIND ('-') command still reach the 1st record in the table (not in the range of record based on my filter commands).
    and, the FIND('+') command reaches the last record in the table. ](*,)

    i'm really clueless. need to meditate, contemplate and concentrate with these texts and manuals. :bug: O:)

    so, i changed everything!

    I made new form: 50005 - AA Shipments, based on Posted Shipments (Form:142), and at Form - OnInit(), i wrote: CHANGECOMPANY('AA'); it works!
    the form can open and show AA company's shipment header list.

    my quest now is to find how to do a passing parameter. i need to open this form:AA shipments from Sales Order form. I will add 1 more Menu Items : Line - "Check AA shipment".

    the passing parameter / filter that i need to make is, on Sales Order Subfom (inside Sale Order form) : Purchase Order No. ; to match with AA shipments . External Document No.

    I cannot use Menu Item properites: RunFormLink ; the datatype is not suitable, one is Code20, the other is Text30.

    How to deal with this?
    how to easily create a control to open other form and immediately giving filter based on a value in certain part of the current form?
    how to convert data type: Code to Text, or vice versa? (is this necessary ?)

    please enlight me and show me the way
    Kind regards, Joe Marselo | see my NAV blog joemarselo.wordpress.com | twitter @joemarselo
  • DaveTDaveT Member Posts: 1,039
    Hi JM,

    on the first point I got the following code to work for me
    Linkedso.CHANGECOMPANY('Temp');
    Linkedso.SETFILTER( "External Document No.", "No." );
    IF Linkedso.FIND('-') THEN
       MESSAGE( 'found '+FORMAT(Linkedso.COUNT) )
    ELSE
       MESSAGE( 'NOT found' );
    

    It should be down to where you call the code from ( I used Form - OnAfterGetRecord() )



    On the second point - there are posts on passing parameters to sub-form post. The concept is that you create a function in the sub-form which sets global variable you need in the subform and then call this function from the main form.

    e.g.

    declare the sub-from as a variable type Form then use the code

    subform.passparm( par1, par2, ... );
    subform.runmodal;

    Alternatively you can create a record variable and filter it down in the main form and use

    subform.settableview( Temprec );

    Hopes this helps
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • j.marseloj.marselo Member Posts: 102
    thanx for your comments DaveT,

    your code:
    Linkedso.CHANGECOMPANY('Temp'); 
    Linkedso.SETFILTER( "External Document No.", "No." ); 
    IF Linkedso.FIND('-') THEN 
       MESSAGE( 'found '+FORMAT(Linkedso.COUNT) ) 
    ELSE 
       MESSAGE( 'NOT found' );
    

    seemed cannot work for me (which I wonder why 8-[ )
    the count show me the numbers of all record in the table, no matter which SO# i'm in.

    I changed your code into:
    nmssh.CHANGECOMPANY('AA');
    aassh.SETFILTER( "External Document No.", "Purchase Order No." );
    IF aassh.FIND('-') THEN
       MESSAGE( 'found '+FORMAT(aassh.COUNT) )
    ELSE 
       MESSAGE( 'NOT found' );
    

    f.y.i, datatype of "Purchase Order No." is Code20 ; datatype of "External Document No." is Text30
    is this a matter?

    thanx.
    Kind regards, Joe Marselo | see my NAV blog joemarselo.wordpress.com | twitter @joemarselo
  • DaveTDaveT Member Posts: 1,039
    Hi JM,

    I was using a sales order no. which is also code 20. I notice a same problem with your code - the changecompany is using nmssh instead of aassh.

    on the face of it it looks like "Purchase Order No." is blank and not filtering - maybe use a setrange instead.

    To check the filter you can use a aassh.getfilter to check that it is set properly.
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • j.marseloj.marselo Member Posts: 102
    Finally, I decide to do a/f:
    I create a new form, and put changecompany('AA') in form - oninit()

    in the Sales Order subform, i add a check shipment sub, basically looked like a/f:
    *aash is Form based on Form:Posted Sales Shipments
    * ssh is Record, Sales Shipment Header

    ssh.CHANGECOMPANY('AA');
    ssh.SETFILTER("External Document No.", Rec."Purchase Order No.");
    aassh.SETTABLEVIEW(ssh);
    aassh.EDITABLE := FALSE;
    aassh.RUNMODAL;


    in finishing touch, i put if... to check and message(...) to humanize the interaction.

    Thanx a lot for your supports
    Kind regards, Joe Marselo | see my NAV blog joemarselo.wordpress.com | twitter @joemarselo
  • DaveTDaveT Member Posts: 1,039
    You're welcome, glad to help
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
Sign In or Register to comment.