NAV 2015 Change company from code

varankam
Member Posts: 8
My idea is to create sales order with published codeunit but I need to create orders in different companies.
Is there way to do this?
CHANGECOMPANY does not really help since I have to validate a lot of fields.
Is there way to do this?
CHANGECOMPANY does not really help since I have to validate a lot of fields.
0
Comments
-
[wrong part of the forum, I think]
The published codeunit will be available for each company, so do not make the 'change company' in NAV but in the calling applicationJan Veenendaal0 -
[yes, wrong part. My mistake]
Published codeunit will have different endpoints for each company. Is it possible to use one endpoint and write to different companies?0 -
[Topic moved from 'NAV/Navision Classic Client' forum to 'NAV Three Tier' forum]Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
The companyname is part of the webservice URL.
You may want to have a look at the function GETURL. This one allows you to dynamically build the required URL for a specific company by parameters:FromURL := GETURL(CLIENTTYPE::SOAP,YourCompany,OBJECTTYPE::Codeunit,YourWSObjectID);
Hope this helps
Andrew0 -
Well. If you want do create a sales order in a particular NAV company from some sales order in some company, then you could create a codeunit which is exposed as a webservice. The companyname in the endpoint is the company in which the sales order will be created. You could pass a companyname and an invoice No. as parameters to this codeunit, and use a CHANGECOMPANY statement inside this codeunit to switch the sales header and lines to the company from which the values are to be read. In this case, the limitations of the CHANGECOMPANY do not play a role since you'll be just copying the values from it and assigning them to the new sales order. All business logic like the OnValidate are executed for this new sales order without using a CHANGECOMPANY statement.
I am using this technique to push items from company A to company B. If item X in company A needs to be copied to company B, I am calling the codeunit with company B in it's endpoint and company A as one of the parameters. This can be done for any table.
If however, you want to create a sales order from some external source, like a XML, then you should call the webservice with the applicable companyname in the endpoint and the contents of the xml as it's parameters.
Although I never tried, I think it's perfectly possible to call a codeunit which is exposed as a webservice, and have this codeunit call another (or even the same) webservice which is a codeunit. And therefore ensuring that all business logic is correctly executed without any limitations. So the aswer is yes. You can call any codeunit in any company from any company.0 -
Thank you Marijn!
I'll try this way.
At the moment I fall to another trouble. If function does not throw an Error than everything in the xmlport was commited even there is error during import.
published function
PostPurchOrder(SourceApp : Text[100];PurchOrderInfo : XMLport "Purch. Order";VAR Response : XMLport Response)
IF NOT PurchOrderInfo.IMPORT THEN BEGIN
AlertMgt.AddAlert(LogEntryNo,0,GETLASTERRORTEXT);
END;
inside xmlport:
OnPostXMLport()
PurchHeader2.INIT;
PurchHeader2.VALIDATE("Document Type", PurchHeader2."Document Type"::Order);
PurchHeader2.INSERT(TRUE);
ERROR(PurchHeader2."No.");
This function creates new Purch Order each time I call it from VS.
I have no idea how to fix it.0 -
Hi,
My advice is to stay away from XMLPorts when they are not used to migrate data from one system into another. I had much trouble too with XMLPorts when used for other purposes like webservices. So I'll suggest you use the XML automations or .NET classes. Examples how to use them can be found anywhere online.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions