AnsweredAssumed Answered

Create Task via Powershell

Question asked by jccote2536 on Jan 30, 2017

After building a new complex workflow with tasks for my customer, I've been asked to migrate in the data from the previous application.  I'm using a PowerShell script to create both the original items and their related tasks.  This involves programatically creating a number of tasks, outside of the normal workflow where the same tasks are normally created.  I've insured that the proper ContentTypeID is being used in creating the tasks, but clearly there's something more I must do.  I'm getting this error, when I go to view the programatically created tasks:

 

The Form layout field value is empty for this Task. Please check if the Activity has been configured with Nintex form and republish the workflow.

 

Clearly there is some kind of value set in the task item when it's created by the workflow, which I am not setting in my PowerShell script.

 

Using the SharePoint REST API with "_api/web/lists(guid'WorkflowTasksGuid')/Items(ItemID)", I did a comparison of the XML, of a task built by the workflow and one built by PowerShell script.  The only difference I could find (other than the task data) was the RelatedItems value set on the workflow-built task, which looks like this:

 

[{"ItemId":<PARENTITEM>,"WebId":<PARENTWEB>,"ListId":<GUID of list with workflow that built the task>}]

 

So I added that into my script, but still got the same error.

 

I'm considering a workaround where I have the workflow build a bunch of empty tasks for each parent item, then use my script to populate the fields in the blanks, and clean up any unused blanks in the end.

 

But for future projects, where legacy data migration is necessary, it would be great to know how to properly build tasks that work the same as if they were built by their parent workflows.

Outcomes