08.05.2008, 22:06 | #1 |
Участник
|
axStart: InfoPath with default AIF web services
Источник: http://axstart.spaces.live.com/Blog/...C0A0!310.entry
============== Introduction When completed this session you have created an InfoPath form that can interact with a Microsoft Dynamics AX Web service. On the end of this document we will use Microsoft Visual Tools for Applications for automatically generate GuidID and Source Endpoint User ID. Also enhancements to the AxdClass will be made. Create a web service in AX
NOTE: only Tables with a unique primary index will work correctly in AIF when you want to find, delete or update the record. Creating the related classes
Change class AxdProjHours method prepareForSave This method is used for additional programming logic. In our casem we have to create a journal. We decide to make a journal for every week. public boolean prepareForSave(AxdStack _axdStack, str _dataSourceName) { ProjJournalTable projJournalTable; JournalID journalID; axProjJournalTrans axProjJournalTrans; ; switch (classidget(_axdStack.top())) { case classnum(AxProjJournalTrans) : axProjJournalTrans = _axdStack.top(); //InfoPath Demo create journal in case not exist journalID = strfmt("Week %1",wkofyr(axProjJournalTrans.parmProjTransDate())); if(!ProjJournalTable::exist(journalID)) { projJournalTable.initFromProjJournalName(ProjJournalName::Find("Hour")); projJournalTable.JournalId = journalID; projJournalTable.insert(); } axProjJournalTrans.parmJournalId(journalID); //InfoPath Demo create journal in case not exist return true; default : error(strfmt("@SYS88979",classId2Name(classidget(_axdStack.top())))); return false; } return false; } Create the new Web service
Create a new Endpoint for the action with additional authorization.
[/FONT] Create an InfoPath document Open InfoPath 2007 on the VPC. Select design a Form Template. Select Web Service and press OK. InfoPath will open a wizard that helps you to find and connect the right way to our AIF ProjHours Web Service. In our case we will Submit Data. The web service is located at http://dynamicsvm/DynamicsWebService/ProjHoursService.asmx. InfoPath will show a list of operations that will submit data. We can only select our creareListProjHours operation. We don’t change the name of this web service because it is still our main submit. Designing the Form Drag the fields to the form that you need. First we drag the DocumentContext node to the design. When dropping it into the design we select ‘Controls in Layout Table’ Next select the end of your document and press Insert/repeating Table. Select the ProjJournalTrans record and press next. Select the fields that are needed for the InfoPath dialog and press Finish Finally give the CurrencyID a default value EUR , by double clicking on the CurrencyID of the datasource and entering the value. Programming in InfoPath We have the general design for our InfoPath dialog available, but we don’t have match intelligence. It would be better if we dynamical generate:
Go to the FormEvents_Loading method and add these lines of code: public void FormEvents_Loading(object sender, LoadingEventArgs e) { string xmpPath = "/dfs:myFields/dfs:dataFields/tns:createListProjHours/tns:DocumentContext"; XPathNavigator xmlGuid = this.MainDataSource.CreateNavigator().SelectSingleNode(xmpPath +"/tns:MessageId", this.NamespaceManager); XPathNavigator xmlEndPointUser = this.MainDataSource.CreateNavigator().SelectSingleNode(xmpPath +"/tns:SourceEndpointUser", this.NamespaceManager); XPathNavigator xmlSourceEndpoint = this.MainDataSource.CreateNavigator().SelectSingleNode(xmpPath + "/tns:SourceEndpoint", this.NamespaceManager); XPathNavigator xmlEndPoint = this.MainDataSource.CreateNavigator().SelectSingleNode(xmpPath + "/tns:DestinationEndpoint", this.NamespaceManager); xmlGuid.SetValue(System.Guid.NewGuid().ToString()); xmlEndPointUser.SetValue(System.Environment.UserDomainName + "\" + System.Environment.UserName); xmlSourceEndpoint.SetValue("Hours"); xmlEndPoint.SetValue("dmo"); } Next Build (compile) your solution in Visual Studio. Close Visual Studio and do your first test in InfoPath by pressing the Preview button. And ……….. we get an error! This error tells us that we are not allowed to check for the user and domain name. Think about secure x++ code you have to ask permission for it. So let’s ask for permission. Close the preview and go back to visual studio and add next line in the FormEvent_loading method new EnvironmentPermission(PermissionState.Unrestricted).Assert(); Also add the library for this Class at top of your c# project using System.Security.Permissions; Now the code is ready for secure coding but our InfoPath Form is not trusted jet. To get our InfoPath trusted, do the next steps:
EmplID RAV ProjID 40010 CategoryID Install Qty 8 LinePropertyID Charge Testing, debugging & fixing If you submit your data and you get an error. The information of this error is a little bit incomplete. Detailed information about the error is available in AX. Look at the Form at Menu/Basic/Periodic/AIF/Exceptions. NOTE AIF will skip fields when the property allowEditOnCeate is set to NO, without any warning Good luck for dowloading the solution: Code + article in pdf format What’s Next Next week we will redesign our InfoPath form so it can interact with AIF file inbound adapter. In the final week we will introduce offline working and automatic synchronization and add lookup fields for selecting project, Employee etc. Источник: http://axstart.spaces.live.com/Blog/...C0A0!310.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
Теги |
aif, axbc, webservice |
|
|