Transform Question - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Transform Question

Last post 09-15-2016 09:10 AM by Hilary Stoupa. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 09-08-2016 08:54 AM

    Transform Question

     Hi All,

    I have a secondary data source from which I want to extract some repeating information and put it in to a repeating group in the main data source. 

    I believe I need to use the Transform command from Q-rules to do this as the data element names are not the same.  Is this correct ?   

    I have had VERY limited experience of writing transforms - does this look to be a  simple transform ?

     

    Main data source   Secondary Data Source  
         <dfs:myFields>   
      <dfs:queryFields> 
      <q:SharePointListItem_RW>
      <q:Title/> 
      <q:SRDate/>
      <q:SRTime/>
      <q:SRTeam/>
      <q:Description/>
      <q:StockType/>
      <q:Value/>
      <q:ID/> 
      </q:SharePointListItem_RW>
      </dfs:queryFields> 
      <dfs:dataFields> 
      <d:SharePointListItem_RW>
    <my:myFields> <d:Title/> 
     </my:FormStatus> <d:SRDate/>
     <my:Stocks> <d:SRTime/>
     <my:StocksTable> <d:SRTeam/>
     <my:Description/><------------------------------------------------------------<d:Description/>
     <my:Type/><------------------------------------------------------------<d:StockType/>
     <my:Count/><------------------------------------------------------------<d:Value/>
     <my:ID/> <d:ID/> 
     </my:StocksTable> </d:SharePointListItem_RW>
     </my:Stocks> </dfs:dataFields> 
    </my:myFields></dfs:myFields> 
              

     

  • 09-08-2016 09:54 AM In reply to

     A transform is going to be much more efficient than the other approach we use with qRules, which is using Insert to insert the same number of rows in the main DS you wish to copy over, then a rule on the StocksTable node to set values. However, if you only have limited rows you'll be copying, you may want to try the Insert approach. Here's a link to a doc on using Insert.

    This does look like it would be a pretty simple transform however - Do you use Visual Studio? You can run your transform in debug with a sample XML, so you can verify the output. Looks like the XML plugin for Notepad++ also has a transform capability. :)

    Hilary Stoupa

  • 09-13-2016 08:56 AM In reply to

    Hi

    I am still playing with my “simple” xslt transform.  I thought I had it sussed when it worked in the online checkers…

    My transform is attached.

    My QRules transform command is Transform /xsltfile=Stocks.xsl /sourceds=Stocks /destpath=/my:myFields/my:Stocks /excluderoot=true

     

    I am getting the error         An error occurred trying to process the result as XML. Data at the root level is invalid. Line 1, position 1.

     

    I am a bit confused whether my destpath should be =/my:myFields/my:Stocks or =/my:myFields/my:Stocks/my:StocksTable - but I don't know if this being wrong would cause the error shown above.


    Is anyone able to point me in the correct direction ?

    Thank you.

    Catharine

    PS the data I tested the transform on is below

      <dfs:myFields xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2016-08-12T14:54:12" xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls" xmlns:ma="http://schemas.microsoft.com/office/2009/metadata/properties/metaAttributes" xmlns:d="http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields" xmlns:q="http://schemas.microsoft.com/office/infopath/2009/WSSList/queryFields" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:dms="http://schemas.microsoft.com/office/2009/documentManagement/types" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003">
       <dfs:queryFields>
        <q:SharePointListItem_RW>
         <q:Title/>
         <q:SRDate/>
         <q:SRTime/>
         <q:SRTeam/>
         <q:Description/>
         <q:StockType/>
         <q:Value/>
         <q:ID/>
        </q:SharePointListItem_RW>
       </dfs:queryFields>
       <dfs:dataFields>
        <d:SharePointListItem_RW>
         <d:Title/>
         <d:SRDate/>
         <d:SRTime/>
         <d:SRTeam/>
         <d:Description>Fred</d:Description>
         <d:StockType>Packet</d:StockType>
         <d:Value>100</d:Value>
         <d:ID/>
        </d:SharePointListItem_RW>
        <d:SharePointListItem_RW>
         <d:Title/>
         <d:SRDate/>
         <d:SRTime/>
         <d:SRTeam/>
         <d:Description>George</d:Description>
         <d:StockType>Bag</d:StockType>
         <d:Value>1000</d:Value>
         <d:ID/>
         </d:SharePointListItem_RW>
        <d:SharePointListItem_RW>
         <d:Title/>
         <d:SRDate/>
         <d:SRTime/>
         <d:SRTeam/>
         <d:Description>Helen</d:Description>
         <d:StockType>Bar</d:StockType>
         <d:Value>900</d:Value>
         <d:ID/>     
        </d:SharePointListItem_RW>
        </dfs:dataFields>
       </dfs:myFields> 

  • 09-13-2016 12:16 PM In reply to

    I made a few changes to your transform in the attached sample file (the "my" namespace didn't match the "my" namespace in your form, and we don't need a for-each, we can use apply-template instead) - but I think I named everything the same in this sample & you'll be able to apply the same command to your form. I also added a command that returns the XML from the transform to another node as a string - that is one of the ways I troubleshoot, because I struggle with the correct syntax for this command myself. :)
    Hilary Stoupa

  • 09-14-2016 06:32 AM In reply to

    Hi Hilary

    Thank you soooo much for the sample I can use the xslt as a template for my other transforms  And I now know how I can see the output of the transform – making diagnosing much easier.

    I have realised that the SharePoint data connection has data in the query half of the data connection

    I have added that to the new 1.xml in the sample (see attached) and now I get an error - An error occurred trying to process the result as XML. Data at the root level is invalid. Line 1, position 1.

    And the output is showing

    2016-08-1811:00Shift A/Twilight<my:Stocks xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2016-09-13T18:54:00" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:d="http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields">

    <my:StocksTable><my:Description>Fred</my:Description><my:Type>Packet</my:Type><my:Count>100</my:Count><my:ID /></my:StocksTable>

    <my:StocksTable><my:Description>George</my:Description><my:Type>Bag</my:Type><my:Count>1000</my:Count><my:ID /></my:StocksTable>

    <my:StocksTable><my:Description>Helen</my:Description><my:Type>Bar</my:Type><my:Count>900</my:Count><my:ID /></my:StocksTable>

    </my:Stocks>


    So it is picking up the information from the q:SharePointListItem_RW  even though the template is trying to match dfs:dataFields

     

    I have changed the commands in the sample to include a  sourcepath

     

    Transform /xsltfile=Stocks.xsl /sourceds=Stocks /sourcepath=/dfs:myFields/dfs:dataFields /destpath=/my:myFields/my:field1 /tostring=true 

    Transform /xsltfile=Stocks.xsl /sourceds=Stocks /sourcepath=/dfs:myFields/dfs:dataFields /destpath=/my:myFields/my:Stocks /excluderoot=true

     

    so the output is now 

    <my:Stocks xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2016-09-13T18:54:00" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:d="http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields">

    <my:StocksTable><my:Description>Fred</my:Description><my:Type>Packet</my:Type><my:Count>100</my:Count><my:ID /></my:StocksTable>

    <my:StocksTable><my:Description>George</my:Description><my:Type>Bag</my:Type><my:Count>1000</my:Count><my:ID /></my:StocksTable>

    <my:StocksTable><my:Description>Helen</my:Description><my:Type>Bar</my:Type><my:Count>900</my:Count><my:ID /></my:StocksTable>

    </my:Stocks>

     

    and I don't get any errors.

     

    In my live form I have done the same.

     

    So the commands are

    Transform /xsltfile=Stocks.xsl /sourceds=Stocks /sourcepath=/dfs:myFields/dfs:dataFields /destpath=/my:myFields/my:Stocks /excluderoot=true

    Transform /xsltfile=Stocks.xsl /sourceds=Stocks /sourcepath=/dfs:myFields/dfs:dataFields /destpath=/my:myFields/my:FormStatus/my:TransformOutput /tostring=true 

     

    The output looks like this

    <my:Stocks xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2016-09-13T18:54:00" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:d="http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields">

    <my:StocksTable><my:Description>M&amp;S Smoke 55g</my:Description><my:Type>Trays</my:Type><my:Count>4</my:Count><my:ID /></my:StocksTable>

    <my:StocksTable><my:Description>M&amp;D un-smoke 55g</my:Description><my:Type>Trays</my:Type><my:Count>8</my:Count><my:ID /></my:StocksTable>

    <my:StocksTable><my:Description>Co-op Strippers</my:Description><my:Type>Cases</my:Type><my:Count>34</my:Count><my:ID /></my:StocksTable>

    </my:Stocks>

     

    But now I have the following as an error - An error occurred setting the result of the transform.  Schema validation found non-data type errors.

    I have checked Description/Type/Count/ID  elements in the main data source and they are all text fields.

    I have obviously done something wrong - any ideas ?

     

    Thank you

    Catharine 

  • 09-14-2016 09:04 AM In reply to

    I would like to point out that I might be an idiot. :) You know I mentioned your "my" namespace was off? Well.... it probably isn't off for your form, but was off for my sample form. In your transform you are using in your "real" form - fix that my namespace to use the correct URL. I'm gonna go die of shame now.
    Hilary Stoupa

  • 09-15-2016 02:19 AM In reply to

     Hi Hilary,

    I have learnt so much with this... I hadn't really looked at the namespace definitions before (duh!) all I saw was "blah blah" - Now I have spent time looking and trying to understand I see includes the date that the form was created - hence the problem.

    I have created and tested a second simple transform from different SharePoint data - this time with the added complication of an if statement - - I know I am just beginning - but I was so pleased when I got it to work.

    Thank you for all your help.

    Catharine 

  • 09-15-2016 08:07 AM In reply to

    You are so welcome - when working with XML, XSLT is wonderful magic. :)
    Hilary Stoupa

  • 09-15-2016 09:01 AM In reply to

     You have created a monster !

    I have now created my 3rd transform...(by copying and editing one that works) so the namespace etc should be correct.

    The output with /tostring=true looks ok, but I am getting "An error occurred setting the result of the transform. Schema validation found non-data type errors."

    One of the fields from SharePoint does have a carriage return in it  - would that be having an effect?

    I cannot see any other difference s

  • 09-15-2016 09:10 AM In reply to

    What are the data types of the fields that will be getting values when the transformed data is inserted into the main data source? Are they all string? any attributes? If anything requires the xsi:nil attribute if blank, that could be the issue.... Another option is to take that transformed XML, paste it into an XML you can preview with, make sure your form versioning is set to NOT update existing XML and preview. Sometimes InfoPath will tell you exactly what node has the schema validation issue.
    Hilary Stoupa

Page 1 of 1 (10 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.