Changecompany for Functions

sabzamsabzam Member Posts: 1,149
Hi Everybody,

I need to run a function for Company B from Company A. Can this be done by using the ChangeCompany Function?

Comments

  • krikikriki Member, Moderator Posts: 9,110
    No, the CHANGECOMPANY is for current record-variable only.
    Be also careful: the record variables used in the triggers (and records of the flowfields) of that record will ALWAYS point to the current company and NOT to the CHANGECOMPANY-company.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    Yes, you can. But be careful. If there are some field validations the code in the validation trigger doesn't recognize that you want to execute it for another company.
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • sabzamsabzam Member Posts: 1,149
    Validation is not an issue. What should I do then to perform the FUnction, because in the records case, the syntax is Record.CHANGECOMPANY(companyname). What is the syntax for the Function?
  • JedrzejTJedrzejT Member Posts: 267
    You can't changecompany for function. Changecompnay is function of record variable. You can changecompany in record var in this function.
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    You don't even need it for function. If you have to do a calculation on variables it's your job to code your function in a way so that the variables contains the correct values.
    If you need table data from another company use record.CHANGECOMPANY. Then do your calculation.

    Maybe it's easier to explain / understand if you decribe what you exactly want to do in your function.
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • sabzamsabzam Member Posts: 1,149
    Thanks for your replies.

    I am replicating the Non-Stock tiems from one company to another, and would like to run the create item functionality from company A, but the item to be created is to be inserted into Company B.

    Therefore I imagine I should simply apply the changecompany functionality for the non-stock item and then simply run the functionality in question, is that correct?
  • sabzamsabzam Member Posts: 1,149
    I have tried to do the create item functionality but the item created is in the company where I'm working from and not in the other company. What shall I do?
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    For that issue there is no simple solution. You have to change the company for each record variable in the function NonstockAutoItem and all sub-functions. And there are some code snippets that may cause an error (I didn't test it), e.g.
    NewItem.VALIDATE("Base Unit of Measure",NonStock2."Unit of Measure");
    
    or
    ItemVend.INSERT(TRUE);
    

    I think you have to copy the functionality and modify it. Try to get your setup information and so on from the other company and create the new item based on a temporary table. After you're done insert the record into the other company by CHANGECOMPANY. I don't know if it fits but it is worth a try.
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • DenSterDenSter Member Posts: 8,305
    I would not go down that road if I were you. Leave core functionality alone, and figure out a way to set up some data ready to be processed in another company, and for instance have NAS pick it up in that other company.

    To be able to run any table logic in another company, you have to do CHANGECOMPANY on EVERY record variable. VALIDATE or INSERT(TRUE) only fails if there are any record variables in the code.

    You would have to modify the entire system to pass a company name into the function, and use that parameter to do CHANGECOMPANY on each and every record variable.

    You have NO IDEA how much work this is, and how much testing this would take. I tried, and after spending about 3 weeks we decided to reserve it all and go at it another way. Not saying it is impossible, just that it is a LOT of work.
  • ta5ta5 Member Posts: 1,164
    I made the same experience as Denster. Try to write the data in a journal or a kind of journal in the other company. Use NAS or a user from the other company to start the processing of these records.
    Thomas
  • einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    DenSter wrote:
    VALIDATE or INSERT(TRUE) only fails if there are any record variables in the code.
    Yes, of course. That is what I mean.
    DenSter wrote:
    Not saying it is impossible, just that it is a LOT of work.
    It depends on the function, but normally that's right.

    One other suggestion:
    Maybe it's easier to execute the function in the target company. Display at the beginning a list of Nonstock Item records of the source company. Then the user has to choose one or more records which will be the base for your new NonstockAutoItem function.
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • idiotidiot Member Posts: 651
    IF inter-company automations is a critical part of the company's business processes, it's better off not using Navision...at the current stage...if upgradability is still part of the goal in the near future...
    It's not natively designed for this kind of processes...
    The ROI for both partner & client is negative...as what DenSter & ta5, including me, experienced...
    NAV - Norton Anti Virus

    ERP Consultant (not just Navision) & Navision challenger
  • DenSterDenSter Member Posts: 8,305
    No I never said that NAV would be bad for inter company transactions, and I never even hinted at any ROI implications.

    What I said was to be cautious using the CHANGECOMPANY command. That has absolutely NOTHING to do with whether NAV would be a suitable platform for intercompany functionality.
  • idiotidiot Member Posts: 651
    What I meant with reference to ROI was the amount of the time invested (you mentioned 3 weeks?) did not yield visible results....Isn't that what you experienced?

    As for the rest of the CHANGCOMPANY comments I speak from personal experience...
    NAV - Norton Anti Virus

    ERP Consultant (not just Navision) & Navision challenger
  • DenSterDenSter Member Posts: 8,305
    idiot wrote:
    What I meant with reference to ROI was the amount of the time invested (you mentioned 3 weeks?) did not yield visible results....Isn't that what you experienced?
    Working 3 weeks at one mod yielded plenty of visible results, we just decided that in our case (considering what we'd just done and where we had yet to go in the project) it was not worth it. We had an alternative that would be much less work and would meet the requirement just as well, so we decided to solve the requirement differently.

    This post is about the use of CHANGECOMPANY, and I added my $0.02 to the discussion. If you want to discuss bigger things such as ROI go ahead, but please don't paraphrase me to make your point.
  • idiotidiot Member Posts: 651
    DenSter wrote:
    idiot wrote:
    What I meant with reference to ROI was the amount of the time invested (you mentioned 3 weeks?) did not yield visible results....Isn't that what you experienced?
    Working 3 weeks at one mod yielded plenty of visible results, we just decided that in our case (considering what we'd just done and where we had yet to go in the project) it was not worth it. We had an alternative that would be much less work and would meet the requirement just as well, so we decided to solve the requirement differently.

    This post is about the use of CHANGECOMPANY, and I added my $0.02 to the discussion. If you want to discuss bigger things such as ROI go ahead, but please don't paraphrase me to make your point.

    Seems our definitions are not along the same line.
    Your "not worth it" is definitely different from my version of "not worth it"...
    Also ROI is bigger picture for you whereas it's the starting point of all my tasks..I will bear that in mind.
    Sorry for the misunderstanding.
    NAV - Norton Anti Virus

    ERP Consultant (not just Navision) & Navision challenger
Sign In or Register to comment.