Posted on 23/02/2024 12:09:13
Here it is:
[EventSubscriber(ObjectType::Codeunit, Codeunit::DynamicwebUsersPublisher, 'OnBeforeGetContactsRequest', '', true, true)]
procedure OnBeforeGetContactsRequest(var requestDoc: XmlDocument; var stopExecution: Boolean; var responseRootNode: XmlNode);
var
pXmlElement: XmlElement;
begin
// Modify requestDoc request xml to your needs
// Set stopExecution := true to cancel base application processing the request
// stopExecution := true;
// If stopExecution set to true you can Set custom xml for the response output
// otherwise base app will append its output to responseDoc
stopExecution := true;
ProcessContactsRequest(responseRootNode);
end;
local procedure ProcessContactsRequest(var xmlRootNode: XmlNode)
var
contact: Record Contact;
pXmlElement: XmlElement;
contactTableXmlNode: XmlNode;
contactNode: XmlNode;
begin
if (contact.FINDSET(false, false)) then begin
//add <table tableName='AccessUser'> xml node
DynamicwebXmlHelper.AddElement(xmlRootNode, 'table', '', '', contactTableXmlNode);
DynamicwebXmlHelper.AddAttribute(contactTableXmlNode, 'tableName', 'AccessUser');
repeat
DynamicwebXmlHelper.AddElement(contactTableXmlNode, 'item', '', '', contactNode);
DynamicwebXmlHelper.AddAttribute(contactNode, 'table', 'AccessUser');
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserUserName', Contact."E-Mail");
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserExternalID', Contact."No.");
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserName', Contact.Name);
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserEmail', Contact."E-Mail");
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserPhone', Contact."Phone No.");
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserFax', Contact."Fax No.");
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserAddress', Contact.Address);
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserAddress2', Contact."Address 2");
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserZip', Contact."Post Code");
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserCity', Contact.City);
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserCountry', Contact."Country/Region Code");
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserCountryCode', Contact."Country/Region Code");
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserAddressTitle', 'Contact address');
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserCompany', Contact."Company Name");
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserActive', 'true');
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserWeb', Contact."Home Page");
DynamicwebXmlHelper.AddField(contactNode, 'AccessUserGroups', 'Customers');
until contact.NEXT = 0;
end;
end;