somebody can explain this codeunit?
OBJECT Codeunit 60000 NAV WS Link Sample
{
OBJECT-PROPERTIES
{
Date=10/11/14;
Time=14.17.33;
Modified=Yes;
Version List=ABS;
}
PROPERTIES
{
OnRun=BEGIN
//CustomerSample('002055', 'CRM Dev BLC');
//CustomerSample('', 'CRM Dev RCA');
MESSAGE(PostSalesDocument(0, '123456', TRUE, TRUE, 'Iperutility Srl'));
END;
}
CODE
{
PROCEDURE InvokeNavWS@1000000002(URL@1000000000 : Text[250];Method@1000000001 : Text[30];Namespace@1000000002 : Text[80];ReturnTag@1000000003 : Text[20];Parameters@1000000004 : Text[1024];VAR NodeList@1000000005 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF82-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNodeList") Result : Boolean;
VAR
xmlHttp@1000000006 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A0A-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.XMLHTTP60";
xmlDoc@1000000007 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A05-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.DOMDocument60";
soapEnvelope@1000000008 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMElement";
soapBody@1000000009 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMElement";
soapMethod@1000000010 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMElement";
node@1000000011 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode";
parametersXmlDoc@1000000012 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A05-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.DOMDocument60";
BEGIN
Result := FALSE;
// Create XML Document
CREATE(xmlDoc,TRUE,TRUE);
// Create SOAP Envelope
soapEnvelope := xmlDoc.createElement('Soap:Envelope');
soapEnvelope.setAttribute('xmlns:Soap', '
http://schemas.xmlsoap.org/soap/envelope/');
xmlDoc.appendChild(soapEnvelope);
// Create SOAP Body
soapBody := xmlDoc.createElement('Soap:Body');
soapEnvelope.appendChild(soapBody);
// Create Method Element
soapMethod := xmlDoc.createElement(Method);
soapMethod.setAttribute('xmlns', Namespace);
soapBody.appendChild(soapMethod);
// Transfer parameters by loading them into a XML Document and move them
CREATE(parametersXmlDoc,TRUE,TRUE);
parametersXmlDoc.loadXML('<parameters>'+Parameters+'</parameters>');
IF parametersXmlDoc.firstChild.hasChildNodes THEN
BEGIN
WHILE parametersXmlDoc.firstChild.childNodes.length>0 DO
BEGIN
node := parametersXmlDoc.firstChild.firstChild;
node := parametersXmlDoc.firstChild.removeChild(node);
soapMethod.appendChild(node);
END;
END;
// Create XMLHTTP and SEND
CREATE(xmlHttp, TRUE, TRUE);
xmlHttp.open('POST', URL, FALSE);
xmlHttp.setRequestHeader('Content-type', 'text/xml; charset=utf-8');
xmlHttp.setRequestHeader('SOAPAction', Method);
xmlHttp.send(xmlDoc);
// If status is OK - Get Result XML
IF xmlHttp.status=200 THEN
BEGIN
xmlDoc := xmlHttp.responseXML;
xmlDoc.setProperty('SelectionLanguage','XPath');
xmlDoc.setProperty('SelectionNamespaces','xmlns:tns="'+Namespace+'"');
NodeList := xmlDoc.selectNodes('//tns:'+ReturnTag);
Result := TRUE;
END;
END;
PROCEDURE EncodeURIComponent@1000000004(URI@1000000000 : Text[250]) EncodedURI : Text[1024];
VAR
HexDigits@1000000001 : Text[30];
i@1000000002 : Integer;
b@1000000003 : Byte;
BEGIN
// No URI Encoding in NAV - we do it ourself...
HexDigits := '0123456789ABCDEF';
EncodedURI := '';
FOR i:=1 TO STRLEN(URI) DO
BEGIN
b := URI
;
EncodedURI := EncodedURI + '% ';
EncodedURI[STRLEN(EncodedURI)-1] := HexDigits[(b DIV 16)+1];
EncodedURI[STRLEN(EncodedURI)] := HexDigits[(b MOD 16)+1];
END;
END;
PROCEDURE DISPLAY@1000000001(s@1000000000 : Text[1024]);
BEGIN
MESSAGE(s);
END;
PROCEDURE ShowCompanies@1000000012(BaseURL@1000000001 : Text[250]);
VAR
NodeList@1000000000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF82-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNodeList";
Node@1000000002 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode";
i@1000000003 : Integer;
Company@1000000004 : Text[100];
BEGIN
CLEAR(NodeList);
IF SystemService_Companies(BaseURL, NodeList) THEN BEGIN
DISPLAY('Companies:');
FOR i:=1 TO NodeList.length DO
BEGIN
Node := NodeList.item(i-1);
DISPLAY(Node.text);
IF i=1 THEN Company := Node.text;
END;
END;
END;
PROCEDURE SystemService_Companies@1000000003(BaseURL@1000000001 : Text[250];VAR NodeList@1000000000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF82-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNodeList") Result : Boolean;
VAR
SystemServiceURL@1000000002 : Text[250];
SystemServiceNS@1000000003 : Text[250];
BEGIN
SystemServiceURL := BaseURL + 'SystemService';
SystemServiceNS := 'urn:microsoft-dynamics-schemas/nav/system/';
Result := InvokeNavWS(SystemServiceURL, 'Companies', SystemServiceNS, 'return_value', '', NodeList);
END;
PROCEDURE CustomerPage_Read@1000000005(No@1000000000 : Text[20];CompanyURL@1000000004 : Text[250];VAR NodeList@1000000001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF82-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNodeList") Result : Boolean;
VAR
CustomerServiceNS@1000000003 : Text[250];
CustomerPageURL@1000000002 : Text[250];
BEGIN
CustomerPageURL := CompanyURL + 'Page/Customer';
CustomerServiceNS := 'urn:microsoft-dynamics-schemas/page/customer';
Result := InvokeNavWS(CustomerPageURL, 'Read', CustomerServiceNS, 'Customer', '<No>'+No+'</No>', NodeList);
END;
PROCEDURE CustomerPage_ReadMultiple@1000000006(Filters@1000000000 : Text[1024];CompanyURL@1000000002 : Text[250];VAR NodeList@1000000001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF82-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNodeList") Result : Boolean;
VAR
CustomerServiceNS@1000000004 : Text[250];
CustomerPageURL@1000000003 : Text[250];
BEGIN
CustomerPageURL := CompanyURL + 'Page/Customer';
CustomerServiceNS := 'urn:microsoft-dynamics-schemas/page/customer';
Result := InvokeNavWS(CustomerPageURL, 'ReadMultiple', CustomerServiceNS, 'Customer', Filters, NodeList);
END;
PROCEDURE CustomerSample@1000000008(CustomerNo@1000000012 : Code[20];CompanyName@1000000013 : Text[100]);
VAR
BaseURL@1000000010 : Text[250];
SystemServiceURL@1000000009 : Text[250];
SoapEnvelopeNS@1000000008 : Text[250];
SystemServiceNS@1000000007 : Text[250];
CustomerServiceNS@1000000005 : Text[250];
NodeList@1000000004 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF82-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNodeList";
Node@1000000003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode";
i@1000000002 : Integer;
cur@1000000001 : Text[250];
CustomerPageURL@1000000000 : Text[250];
CompanyURL@1000000011 : Text[250];
BEGIN
BaseURL := 'http://SV-IU-DEV.sv-iu.iperutility:7107/DynNav71_VT7-TEST/WS/';
//IF NOT Misc.EndsWith(BaseURL, '/') THEN BaseURL += '/';
IF CompanyName = '' THEN
CompanyURL := BaseURL + EncodeURIComponent('')
ELSE
CompanyURL := BaseURL + EncodeURIComponent(CompanyName);
//IF NOT Misc.EndsWith(CompanyURL, '/') THEN CompanyURL += '/';
CustomerServiceNS := 'urn:microsoft-dynamics-schemas/page/customer';
CustomerPageURL := CompanyURL + 'Page/Customer';
DISPLAY('URL of Customer Page: '+ CustomerPageURL);
IF CustomerNo <> '' THEN BEGIN
IF CustomerPage_Read(CustomerNo, CompanyURL, NodeList) THEN
BEGIN
DISPLAY('Name of Customer ' + CustomerNo + ': ' + NodeList.item(0).childNodes.item(2).firstChild.text);
END;
END ELSE BEGIN
IF CustomerPage_ReadMultiple('<filter><Field>Country_Region_Code</Field><Criteria>US|USA|''''</Criteria></filter>',
CompanyURL ,NodeList) THEN
BEGIN
FOR i:=1 TO NodeList.length DO
BEGIN
Node := NodeList.item(i-1);
DISPLAY(Node.childNodes.item(2).firstChild.text);
END;
END;
DISPLAY('THE END');
END;
END;
PROCEDURE PostSalesDocument@1000000000(DocumentType@1000000001 : Integer;DocumentNo@1000000000 : Code[20];Ship@1000000010 : Boolean;Invoice@1000000011 : Boolean;CompanyName@1000000002 : Text[100]) Status : Text[1024];
VAR
InterCompanyServiceURL@1000000004 : Text[250];
InterCompanyServiceNS@1000000005 : Text[250];
Result@1000000006 : Boolean;
Parameters@1000000007 : Text[1024];
NodeList@1000000008 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF82-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNodeList";
Node@1000000009 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode";
BaseURL@1000000019 : Text[250];
CompanyURL@1000000017 : Text[250];
i@1000000012 : Integer;
BEGIN
BaseURL := 'http://SV-IU-DEV.sv-iu.iperutility:7107/DynNav71_VT7-TEST/WS/';
IF CompanyName <> '' THEN
CompanyURL := BaseURL + EncodeURIComponent(CompanyName);
InterCompanyServiceURL := CompanyURL + 'Page/NavWSFunctions';
InterCompanyServiceNS := 'urn:microsoft-dynamics-schemas/codeunit/NavWSFunctions';
Parameters := '<documentType>' + FORMAT(DocumentType) + '</documentType>' +
'<No>' + DocumentNo + '</No>';
CLEAR(NodeList);
Result := InvokeNavWS(InterCompanyServiceURL, 'ClientiVEGAS',
InterCompanyServiceNS, 'return_value', Parameters, NodeList);
IF Result THEN BEGIN
IF NodeList.length > 0 THEN BEGIN
Node := NodeList.item(0);
Status := Node.text;
END ELSE BEGIN
Status := 'Unknown Return Format';
END;
END ELSE BEGIN
Status := 'Failure in Web Service Call';
END;
END;
BEGIN
END.
}
}
Comments
And used for testing webservices it seems.
What do you want to do with it? Or did you ran in to this codeunit and want to clean up the database?
Tino Ruijs
Microsoft Dynamics NAV specialist
From NAV2013 from server A
I need to call a function positioned in one codeunit in another NAV2013 server B, and I would like to pass some parameters by XML file, how in the preview post.
I had published one codeunit with the webservice on the NAV2013 server B, the goal is to get a company name of a specific customer
any suggestion?