cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Creating an item programatically won't start a Nintex Workflow

Jump to solution

When you create an item on a list programatically, it says Created By: System Account.

After a research, I know that is a known issue when the Inititar is System Account, the Workflow won't start. Although, I'm based on this threads, which are somewhat old (circa 2010):

Nintex Connect - workflow does not start when list item is created programmatically

Nintex Connect - Nintex Workflow Not Starting Automatically When a new item is created

Nintex Connect - Workflow doesn't start if items are created programmatically

 

So, I wanted to ask here, to be sure if there isn't a workaround about this issue now.

 

Any help would be appreciated.

Labels: (2)
0 Kudos
Reply
7 Replies
Workflow Hero

Re: Creating an item programatically won't start a Nintex Workflow

Jump to solution

You can definitely have workflows start when an item is created pragmatically. I've been able to do this in many of my solutions for SharePoint. There are some tips, like the one you mentioned. I'll also share a post that may provide some help Value cannot be null. Parameter name: s  This post was about updating items via PowerShell and trying to get the workflows to trigger.

About the System Account, do you have to create the item in an elevated state?

And would the option of starting the workflow via code be possible?

0 Kudos
Reply
Workflow Hero

Re: Creating an item programatically won't start a Nintex Workflow

Jump to solution

it may be a case of allowing..


Stsadm –o setproperty –pn  declarativeworkflowautostartonemailenabled –pv true


I know this is for emails starting the workflow but it is exactly the same issue.. due to it being a system account.

0 Kudos
Reply
Workflow Hero

Re: Creating an item programatically won't start a Nintex Workflow

Jump to solution

You can do it also with powershell script

to see actual settings

$spWebService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$spWebService
.DeclarativeWorkflowAutoStartOnEmailEnabled

to change settings

$spWebService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$spWebService
.DeclarativeWorkflowAutoStartOnEmailEnabled = $true
$spWebService
.Update()

i found it here

Creating item in list using workflow doesn't trigger item created workflow - SharePoint Stack Exchan...

this worked for me

0 Kudos
Reply
Not applicable

Re: Creating an item programatically won't start a Nintex Workflow

Jump to solution

Yeah, starting the workflow via code is a good idea. But, how do I do this?

0 Kudos
Reply
Not applicable

Re: Creating an item programatically won't start a Nintex Workflow

Jump to solution

Thanks for your answer.

Do you know if it would be the same to call the webapi of nintex by code?

0 Kudos
Reply
Workflow Hero

Re: Creating an item programatically won't start a Nintex Workflow

Jump to solution

See if the declarativeworkflowautostartonemailenabled helps first. You can start the workflow through the SharePoint API using workflowmanager. This should get you started.

 

public void StartWorkflow(SPListItem listItem, SPSite spSite, string wfName)  {

  SPList parentList = listItem.ParentList;

  SPWorkflowAssociationCollection associationCollection = parentList.WorkflowAssociations;

  foreach (SPWorkflowAssociation association in associationCollection)  {

  if (association.Name == wfName){

    association.AssociationData = string.Empty;

    spSite.WorkflowManager.StartWorkflow(listItem, association,  association.AssociationData);

  }

  }

}

0 Kudos
Reply
Not applicable

Re: Creating an item programatically won't start a Nintex Workflow

Jump to solution

Sorry for taking so long in replying.

I want to let you know that the code you gave worked like charm. Thank you very much.

0 Kudos
Reply