Query XML count zero

  • 6 September 2017
  • 8 replies
  • 16 views

Badge +1

Hi,

I've a Web Request which gets data from SharePoint using GET method and I've stored the XML response in a variable called "ResponseContent".

To Extract data, I've used Query XML action and passing XML source's content as {Variable:ResponseContent} 

My XML looks like this:

<?xml version="1.0" encoding="utf-8"?>
<feed xml:base="https://mysite/sites/w/ProjRequest/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
  <id>f75e5831-abb3-44a7-aff8-8348d2fc33ab</id>
  <title />
  <updated>2017-09-05T14:09:33Z</updated>
  <entry m:etag="&quot;8&quot;">
    <id>Web/Lists(guid'77e2432b-22e9-479d-885a-d7134f3034f9')/Items(32)</id>
    <category term="SP.Data.Project_x0020_Request_x0020_listItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <link rel="edit" href="Web/Lists(guid'77e2432b-22e9-479d-885a-d7134f3034f9')/Items(32)" />
    <title />
    <updated>2017-09-05T14:09:33Z</updated>
    <author>
      <name />
    </author>
    <content type="application/xml">
      <m:properties>
        <d:Title>2016-06-10T14_27_36.xml</d:Title>
        <d:Project_x0020_Name>ProjectName1</d:Project_x0020_Name>
        <d:Department_x0020_01>Business Development</d:Department_x0020_01>
      </m:properties>
    </content>
  </entry>
  <entry m:etag="&quot;8&quot;">
    <id>Web/Lists(guid'77e2432b-22e9-479d-885a-d7134f3034f9')/Items(34)</id>
    <category term="SP.Data.Project_x0020_Request_x0020_listItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <link rel="edit" href="Web/Lists(guid'77e2432b-22e9-479d-885a-d7134f3034f9')/Items(34)" />
    <title />
    <updated>2017-09-05T14:09:33Z</updated>
    <author>
      <name />
    </author>
    <content type="application/xml">
      <m:properties>
        <d:Title>2016-06-14T15_24_09.xml</d:Title>
        <d:Project_x0020_Name>ProjectName2</d:Project_x0020_Name>
        <d:Department_x0020_01>USA</d:Department_x0020_01>
      </m:properties>
    </content>
  </entry>
  <entry m:etag="&quot;8&quot;">
    <id>Web/Lists(guid'77e2432b-22e9-479d-885a-d7134f3034f9')/Items(35)</id>
    <category term="SP.Data.Project_x0020_Request_x0020_listItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <link rel="edit" href="Web/Lists(guid'77e2432b-22e9-479d-885a-d7134f3034f9')/Items(35)" />
    <title />
    <updated>2017-09-05T14:09:33Z</updated>
    <author>
      <name />
    </author>
    <content type="application/xml">
      <m:properties>
        <d:Title>2016-06-14T15_25_38.xml</d:Title>
        <d:Project_x0020_Name>ProjectName3</d:Project_x0020_Name>
        <d:Department_x0020_01>Production Management</d:Department_x0020_01>
      </m:properties>
    </content>
  </entry>
</feed>

My XPath query is /feed/entry/content/m:properties/d:Title

Return result as Text

Query result in VarCollection

 

To Count the collection, I've used "Count Items in Collection" Action

Target Collection as VarCollection

Total items as VarCount

 

I've published this workflow. When I ran this workflow, I'm getting VarCount as 0

 

My Intention is to get each m:properties stored in a collection and add it to current list as new list item. But I'm stuck on the above issue.

 

Could you please help me out here ?

 

Thanks,

Pandiarajan


8 replies

Userlevel 6
Badge +13

Store the response in a Dictionary and then use the action "Get Item from Dictionary" and then set "Item name or path" to d/results and store the results in another dictionary variable.

Then use "Count Items in a Dictionary" and count your new dictionary output the total in a variable.

You can then use a loop to iterate through as many times as your "count" variable says you need to and use the "Get item from dictionary" action inside your loop to get the output of the index and then increment. 

d/results({Variable:LoopCounter})/Title

d/results({Variable:LoopCounter})/Project_x0020_Name

d/results({Variable:LoopCounter})/Department_x0020_01

use this action for each of the properties, store them in a variable and then create your new item before incrementing the index looping again until your index is equal to your count.

Does this make sense?

‌ 

Badge +1

Hi Ryan

Thanks for your reply.

I have added header Accept = application/json to get JSON Results from Web request.

I cannot store the response from Web Request action to Dictionary.

I'm trying to get list values from SharePoint on-premise. I must have to use Web request here because Call HTTP Request is not supporting credentials. There is no provision to save response content(for this action) to Dictionary. Where as Call HTTP Service action has option to save response content to dictionary. Also, Web Request has option to save response to Text Variable, I tried saving this Text variable to Dictionary using Set Workflow Variable action but it is still not working.

Am I doing anything wrong here?

.

Regards,

Pandiarajan

Userlevel 6
Badge +13

OK, so this is an O365 workflow calling an on-prem webservice?

Badge +1

Yes. You're right

Badge +1

Hi Ryan,

Any alternative ways to accomplish this task?

Thanks

Badge +1

‌ Expert advise here?

Userlevel 7
Badge +17

Hi!

Why don't you just use the simpler xpath: //m:properties

Or //m:properties/d:Title, and so on? That works

Regards,

Tomasz

Badge +2

I am having the same issue, any response please? I have tried to log the response in history list and it is always logging "0"

Reply