I'm a Drupal nubie. I develop a extranet portal for my client using Drupal 7 that consumes Web Services from SOAP WSDL using Rule. I'm having trouble with Rule loops over result arrays.
I can successfully consume and display, say, the web service "API Version" which is a single result object.
Yet I'm having trouble with Rule loops when my result returns an array of items. It's an array of Tickets in this case. I see the result contains 10 Ticket objects, each as a stdClass Object. Yet I cannot do anything with them. I'm not sure if Drupal Rules creates an error or if I simply use this Rules module incorrectly. I added a "Show Message on the Site" of the word "iter" within the loop, yet it never shows, not once, let alone 10 times.
When I view my created Tickets content, I see none of my tickets. I see no "Iter" message shown on the site. I get the error:
Warning: array_keys() expects parameter 1 to be array, object given in array_keys() (line 1040 of /Applications/MAMP/htdocs/drupal/sites/all/modules/entity/includes/entity.wrapper.inc). =>
... dump here
Recoverable fatal error: Argument 2 passed to EntityMetadataWrapperIterator::__construct() must be of the type array, null given, called in /Applications/MAMP/htdocs/drupal/sites/all/modules/entity/includes/entity.wrapper.inc on line 1040 and defined in __construct() (line 1118 of /Applications/MAMP/htdocs/drupal/sites/all/modules/entity/includes/entity.wrapper.inc). =>
... dump here
Am I missing something obvious? What am I doing wrong? Please help!
Here is my exported Rule, triggered on When Content viewer, of condition Content is of type CW Ticket:
{ "rules_cw_tickets" : {
"LABEL" : "Rule CW Tickets",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "wsclient" ],
"ON" : [ "node_view" ],
"IF" : [
{ "node_is_of_type" : {
"node" : [ "node" ],
"type" : { "value" : { "cw_ticket" : "cw_ticket" } }
}
}
],
"DO" : [
{ "data_create" : {
"USING" : {
"type" : "wsclient_cw_service_ticket_ApiCredentials",
"param_CompanyId" : "FOOOO",
"param_IntegratorLoginId" : "BAAAAR",
"param_IntegratorPassword" : "PASSSSS"
},
"PROVIDE" : { "data_created" : { "data_credential" : "Data Credential" } }
}
},
{ "data_create" : {
"USING" : {
"type" : "wsclient_cw_service_ticket_FindServiceTickets",
"param_credentials" : [ "data-credential" ],
"param_limit" : "10",
"param_skip" : "0"
},
"PROVIDE" : { "data_created" : { "data_fst" : "Data FindServiceTickets" } }
}
},
{ "wsclient_cw_service_ticket_FindServiceTickets" : {
"USING" : { "param_parameters" : [ "data-fst" ] },
"PROVIDE" : { "result" : { "result" : "FindServiceTicketsResponse" } }
}
},
{ "LOOP" : {
"USING" : { "list" : [ "result:FindServiceTicketsResult" ] },
"ITEM" : { "list_item" : "Current list item" },
"DO" : [
{ "data_set" : {
"data" : [ "node:field-srservicerecid" ],
"value" : [ "list-item:SRServiceRecID" ]
}
},
{ "data_set" : {
"data" : [ "node:field-companyname" ],
"value" : [ "list-item:CompanyName" ]
}
},
{ "drupal_message" : { "message" : "Iter." } }
]
}
}
]
}
}
Comments
Bump
Anyone?
+1
Have the same issue, really no one out there?
A solution
I managed to get this to work - seems the problem is that we try to iterate through a PHP array and not a list. I managed to solve this by:
1. Create a variable containing a comma-separated list with php (Add action -> add variable)
2. Explode this variable by using Explode text from module Rules Data Transforms. (Now you have a list that is iteratable)
3. Loop through the list and do your stuff.
Maybe not the cleanest solution, but it works for me. Hope it helps!