Modify Workflow Definition XML via Web Services

Justin "JET" Turner's Avatar

Justin "JET" Turner

10 Jun, 2013 07:57 PM

Hello,

We have a fairly generic workflow definition we use for each site. The primary difference from one site to another is the workflow name (named after the department for easy recognition in emails), and the default-group attribute of an unordered step (the group of editors for that site).

I thought that maybe I could just read the XML, do a quick find and replace and then set the XML back, this throws the following error:

PHP Fatal error:  Uncaught SoapFault exception: [soapenv:Server.generalException] Validation error: cvc-complex-type.2.4.b: The content of element 'ns1:asset' is not complete. One of '{"http://www.hannonhill.com/ws/ns/AssetOperationService":workflowConfiguration, "http://www.hannonhill.com/ws/ns/AssetOperationService":feedBlock, "http://www.hannonhill.com/ws/ns/AssetOperationService":indexBlock, "http://www.hannonhill.com/ws/ns/AssetOperationService":textBlock, "http://www.hannonhill.com/ws/ns/AssetOperationService":xhtmlDataDefinitionBlock, "http://www.hannonhill.com/ws/ns/AssetOperationService":xmlBlock, "http://www.hannonhill.com/ws/ns/AssetOperationService":file, "http://www.hannonhill.com/ws/ns/AssetOperationService":folder, "http://www.hannonhill.com/ws/ns/AssetOperationService":page, "http://www.hannonhill.com/ws/ns/AssetOperationService":reference, "http://www.hannonhill.com/ws/ns/AssetOperationService":xsltFormat, "http://www.hannonhill.com/ws/ns/AssetOperationService":scriptFormat, "http://www.hannonhill.com/ws/ns/As in [path]\new-site.php on line 327

I've built the following function to make the changes to our workflows, but I get basically the same error as above even when just trying to change the name.

function modifyWorkflowDefinition($item, $newName, $changeUsers)
{
    global $auth, $client, $siteName, $groupName;
    $identifier = array
    (
        'path' => array(
            path => $item,
            siteName => $siteName),
        'type' => 'workflowdefinition'
    );
    $readParams = array ('authentication' => $auth, 'identifier' => $identifier);
    $reply = $client->read($readParams);
    echo "<pre>";
    print_r($reply);
    echo "</pre>";
    $asset = $reply->readReturn->asset->workflowDefinition;
    $asset->name = $newName;
    if($changeUsers)
    {
        $xml = $asset->xml;
        echo $xml."<br>";
        $xml = str_replace('department-name',$siteName,$xml);
        $xml = str_replace('default-group="Administrators"','default-group="'.$groupName.'"',$xml);
        $asset->xml = $xml;
        echo $xml;
    }
    $editParams = array('authentication' => $auth, 'asset' => array('workflowdefinition' => $asset));
    $reply = $client->edit($editParams);
    if($reply->editReturn->success=='true')
        echo " Success<br>";
    else
        echo " Fail<br>";
}
  1. 1 Posted by Ryan Griffith on 10 Jun, 2013 08:16 PM

    Ryan Griffith's Avatar

    Hi Justin,

    I noticed the following line uses workflowdefinition as opposed to workflowDefinition.

    $editParams = array('authentication' => $auth, 'asset' => array('workflowdefinition' => $asset));

    Try tweaking this to the following and let me know if this fixes things or produces an error:

    $editParams = array('authentication' => $auth, 'asset' => array('workflowDefinition' => $asset));

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by Justin &quot;JE... on 10 Jun, 2013 08:24 PM

    Justin &quot;JET&quot; Turner's Avatar

    That got rid of the error, I must have copied the 'type' from the identifier instead of the variable name from the print_r.

    The code changed the group, but didn't actually rename the item inside of cascade.
    I tried adding $asset->path = 'UNG/'.$newName; but it still isn't performing the rename. Is there something else that needs to be done to perform a rename? Maybe call the move function?

  3. 3 Posted by Justin &quot;JE... on 10 Jun, 2013 08:33 PM

    Justin &quot;JET&quot; Turner's Avatar

    Yep, the move command did the trick.

  4. Justin "JET" Turner closed this discussion on 10 Jun, 2013 08:33 PM.

  5. Ryan Griffith re-opened this discussion on 10 Jun, 2013 08:38 PM

  6. 4 Posted by Ryan Griffith on 10 Jun, 2013 08:38 PM

    Ryan Griffith's Avatar

    Glad to hear that did the trick. Correct, the move/rename operation would be used to change the Asset's path and name.

    Please let me know if you have any questions.

    Thanks!

  7. Justin "JET" Turner closed this discussion on 11 Jun, 2013 11:42 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac