How to lookup to company B.customer from Company A

RachelSoonRachelSoon Member Posts: 202
hi there,
i would like to know what is the method to look up to CompanyB.customer from Company A.

My coding is as below, but the lookup giving the Customer within the Company A.
Please suggest any method to do the lookup the data to other company book.

Cust.CHANGECOMPANY("OtherCompanyName");

CustCard.SETTABLEVIEW(Cust);
CustCard.SETRECORD(Cust);
CustCard.LOOKUPMODE(TRUE);
IF CustCard.RUNMODAL = ACTION::LookupOK THEN BEGIN
CustCard.GETRECORD(Cust);
message(Cust."No.");
END;

Thank you.

regards,
rachel

Comments

  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    The only way to achieve this is using a temporary record and store the values in that first.

    Then make sure that the form in not editable.
  • reijermolenaarreijermolenaar Member Posts: 256
    Hi Rachel,

    There are two other ways to do this.

    1.

    Don't run the form as a variable but with an id.
    Cust.CHANGECOMPANY(OtherCompanyName);
    IF FORM.RUNMODAL(FORM::"Customer List", Cust) = ACTION::LookupOK THEN
      MESSAGE(Cust."No.");
    

    2.

    Do the ChangeCompany also in the OnOpenForm trigger.
    You first have to set the companyname with a function in the form.

    Cust.CHANGECOMPANY(OtherCompanyName);
    CustList.SetOtherCompany(OtherCompanyName);
    CustList.SETTABLEVIEW(Cust);
    CustList.LOOKUPMODE(TRUE);
    IF CustList.RUNMODAL = ACTION::LookupOK THEN BEGIN
      CustList.GETRECORD(Cust);
      MESSAGE(Cust."No.");
    END;
    

    Form - OnOpenForm()
    IF OtherCompanyName <> '' THEN
      CHANGECOMPANY(OtherCompanyName);
    
    Reijer Molenaar
    Object Manager
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Hi Rachel,

    There are two other ways to do this.

    1.

    Don't run the form as a variable but with an id.
    Cust.CHANGECOMPANY(OtherCompanyName);
    IF FORM.RUNMODAL(FORM::"Customer List", Cust) = ACTION::LookupOK THEN
      MESSAGE(Cust."No.");
    

    :thumbsup: Interesting, I never tried it this way, I have always done it the second way you describe changing company directly on the form from a function.

    What happens to flow fields drill downs subforms etc when you do it this way? (Yeah I know I could try, but it's easier to just ask :mrgreen: )
    David Singleton
  • reijermolenaarreijermolenaar Member Posts: 256
    I didn't tested it but I'm pretty sure that the changecompany doesn't apply to anything else but the REC of the form. So even the values in the flowfields are showing 'wrong' amounts.
    Reijer Molenaar
    Object Manager
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    I would at least make a special Customer Card form for this, preferably non-editable. People will start using the lookups and menuitems and find out they work in another company.

    The temporary table will make sure that you don't start making changes that you don't expect.
  • Purvesh_MaisuriaPurvesh_Maisuria Member Posts: 71
    Hello Mark / reijermolenaar,

    I found it is interesting topic & thanks to reijermolenaar that sharing this great trick =D> =D> =D> .

    I did some R & D related this.

    1. Flow Field's Value is displayed Correct, It get whole record from other company.
    2. Look Up : Displayed other company's data correctly, BUT user can insert & edit data of other company which is wrong.
    3. Drill Down : Displayed other company's data correctly, BUT user can insert & edit data of other company which is wrong.
    4. Go to Card : Displayed the record of current company's data if available,
    if not available then also it is display on card with same no. of other company's no. with all field blank.
    if we insert something there then system insert that record in current company.
    if we not make change then nothing changed.
    5. Editable Fields : Dangerous, User can make any changes.

    Thanks & Regards,
    Purvesh Maisuria.
  • reijermolenaarreijermolenaar Member Posts: 256
    Thanks Purvesh.

    I didn't know that flowfields were respecting the changecompany.
    Learning everyday something new.
    Even in the weekend! :mrgreen:
    Reijer Molenaar
    Object Manager
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    I didn't know about the flowfields either. That's why I love the community.

    Reading the testresults I can only emphasise to please make a different cardform for this and block anything that can cause unexpected behaviour.

    Changecompany has been discussed many times weather or not to make it smarter or not.
  • DenSterDenSter Member Posts: 8,305
    I knew that flowfields follow CHANGECOMPANY and that they display the right values, I was actually shocked at the time that it worked, but very happy because I had to do extensive programming around some multicompany development that I was doing at the time.

    As far as using the normal Card form that definitely NOT OK, because everything else will show the company that you're logged into. If you really want to have a Card form that looks exactly the same, and acts exactly the same, you will have to create a new form and program the crap out of it.

    You have absolutely no idea how much work this is....

    After all these years, people still do not take proper precautions when advising others about working with CHAMGECOMPANY.... ](*,)
Sign In or Register to comment.