AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 20.05.2008, 19:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,631 / 848 (80) +++++++
Регистрация: 28.10.2006
axStart: InfoPath with default AIF file inbound offline
Источник: http://axstart.spaces.live.com/Blog/...C0A0!332.entry
==============

Introduction


Last week we were able to integrate InfoPath with the AIF File Inbound Adapter. Now it’s time for the final blow!
  • Make it possible to work offline and synchronize automatically.
  • Pull down with possible information to fill in (project, category, etc)
    Validation (is Project & category allowed to use)

  Offline working


There is a general option on our Windows operation system that offers offline working. It is on the same place where you normally share a folder. Select Sharing, press Caching button and select option that makes it offline available.

An offline map is actually some kind of file that exists on the client PC. It gets synchronized every time a network connection exists between the client and the server.
Look at Window Start/All Programs/ Accessories/Synchronize (sorry for the Dutch layout). It contains my InfoPath document and one posted xml message.



The user can synchronize manually, at log on or log off time.   Pull down data in InfoPath


Introduction
It is possible to create pull down selection boxes in InfoPath. These pull down boxes can have predefined information or information from an external connection (web service, Database, XML). We will use the XML file. The trick is this: Create for every pull down menu an XML file. Below is an example of the ProjID.

 
    40010
    The Glass Bulb
 
 
    40020
    The Radiant Idea
[FONT='Arial','sans-serif'] 
[/FONT]

  Create a XML files with AX:
  • Create a query on the ProjTable
  • Run the AXd wizard in AX.
    Run the next job, The XSLT is also available in this document
static void projTableXML(Args _args)
{
    ProjTable           projTable;
 
    AifEntityKey        aifEntityKey;
    List                     keyFields        = SysDictTable::getUniqueIndexFields(tablenum(ProjTable));
    AxdProjTable       axdProjTable     = AxdBase::newClassId(classnum(AxdProjTable));
    AifEntityKeyList   aifEntiryKeyList = new AifEntityKeyList();
    AifDocumentXml   aifDocumentXml;
    Map keyMap;
 
    //creating the xml file
    XmlReader xslt;
    XmlReader xml;
    XmlDocument xmlDocument;
    ;
     // add all records to be exported into the entity key list
    while select projTable
    {
        keyMap       = SysDictTable::mapFieldIds2Values(keyFields,projTable);
        aifEntityKey = aifEntityKey::construct();
        aifEntityKey.parmKeyDataMap(keyMap);
        aifEntityKey.parmTableId(projTable.TableId);
        aifEntityKey.parmRecId(projTable.RecId);
        aifEntiryKeyList.addEntityKey(aifEntityKey);
    }
 
    // create an xml document containg the records
    aifDocumentXml = axdProjTable.readList(aifEntiryKeyList,
                                     null,
                                     new AifEndpointActionPolicyInfo(),
                                     new AifConstraintListCollection(),
                                     connull());
    //translate document with XSLT
    xml  = XmlReader::newXml(aifDocumentXml);
    xslt = XmlReader::newFile('C:\AIF\code\xslt\ProjTable.xslt');
    xmlDocument = xmlDocument::newXml(XmlTransform::execute(xslt,xml,false));
    xmlDocument.save('C:\AIF\Inbound\xmlDatabase\ProjTable.xml');
}

XSLT for translation of the ProjTable


           
                       
           



           
                       
           
           
                       
           




For details about XSLT look at other posts on this weblog. Using the xml (off line DB) in InfoPath


Change field to Pull down Box
  • Right mouse click on the ProjId ID field in your InfoPath Design.
    Select change to/Drop – Down List Box
Add lookup XML file
  • Double click on the ProjId ID field
  • Select Look_up values from an external data source
  • Select receive Data, press Next
  • Select XML Document and press Next
  • Browse \Dynamicsvm\Inbound\xmlDatabase\ProjTable.xml, Use the filepath!
    Select Access the data from specified location (So when the XML get’s updated we don’t have to update InfoPath.
Press the button on the right of the Entries field and select the Record node, The value Node is ProjId and the displayname is name
 

Testing
Press Preview Button and test the Pull down.

 
We have to repeat all these steps for Employee, Category and Activity. Creating Validation Logic in your InfoPath Form


You can make field mandatory, and make changes on field trigger other fields. The rules that I used:
  1. EmplID, ProjID, Category ID become mandatory fields.
  2. When changing the EmplID, ProjID, CategoryID and ActivityID Fields get cleared
  3. When changing the ProjID,  CategoryID and ActivityID Fields get cleared.
  4. When Empl ID field is empty ProjID, CategoryID and ActivityID are disabled.
  5. When ProjID field is empty  CategoryID and ActivityID are disabled.
  6. When CategoryID field is empty ActivityID is disabled.
  7. When changing ProjID, validate if employee is allowed to post on that project (c# code)
    When changing CategoryID, check if Category is allowed on that Project (c# code)
Point 1 till 6 can be achieved using conditional formatting and validation rules.
Point 7 & 8 are a little more complex. The information about Employee , Project and Activity relations are stored in AX (ProjValProjCategorySetUp + ProjValEmplProjSetup). This information needs also to be stored in an offline xml file.
Example of a validation xml file (created with AX and XSLT)

 
    AFE
    40010
 
 
    ALT
    40010
 


 
Programming the validation
  • Add the xml data source to the InfoPath Form
  • Tools/Data Connection
  • Select a receive xml file
  • Browse to the xml file \Dynamicsvm\Inbound\xmlDatabase\ProjValEmplProjSetup.xml
  • Select access from existing location
    Don’t Change the data source name otherwise the next code will not work (ProjValEmplProjSetup)
 
Right click on the Proj ID field, select Programming/ Validate event.
public void ProjId_Validating(object sender, XmlValidatingEventArgs e)
 {
   if (e.Site.Value != "") //validate event is also fired when form opens first time
   {
      XPathNavigator      root = this.MainDataSource.CreateNavigator();
      XPathNavigator      EmplNode = root.SelectSingleNode("/ns1:Envelope/ns1:Body/ns2:ProjHours/ns2:ProjJournalTrans/ns2:EmplId", this.NamespaceManager);
      XPathNavigator      ProjValEmplProjSetup = this.DataSources["ProjValEmplProjSetup"].CreateNavigator();
      XPathNodeIterator   ProjValEmplProjSetupResults = ProjValEmplProjSetup.Select("/ProjValEmplProjSetup/record[Projid=" + e.Site.Value + "]/EmplId");
          
      while (ProjValEmplProjSetupResults.MoveNext())
      {
           if (ProjValEmplProjSetupResults.Current.Value == EmplNode.Value)
           {
                  return;
            }
      }
      e.ReportError(e.Site, false, "Employee is not allowed to post on this journal");
    }
 }

 [FONT='Arial','sans-serif'] [/FONT]  Conclusion:


We have build an InfoPath document that interact with the AIF File Inbound Adapter. The concept has a lot of similarities with MS Snap and other solutions on the Internet. Personally I like this approach, because it is simple! Remember InfoPath is flexible it can act like a page in SharePoint or become part of outlook Also the performance of the file inbound with offline xml is higher. The only main difference is: My InfoPath has become a synchronic. But is this bad? Of course there are many other opinions about it. 
Chose the solution you and your customer trust and build it!
download article in PDF format + code
  integration example with outlook

 

Источник: http://axstart.spaces.live.com/Blog/...C0A0!332.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
axStart: When is my Label file updated in AX? Blog bot DAX Blogs 8 28.01.2010 22:09
axStart: Enrich AIF with the power of offline working (roadmap) Blog bot DAX Blogs 0 07.05.2008 15:05

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 01:29.