Hi everyone,
I am a little bit lazy here to write anything :) So just a quick briefing:
1) When you use CreateTaskWithContentType activity you should create your content type or use existing content type
2) Used content type should be derived from Workflow Task Content Type
3) Second point could be a problem since Workflow Task Content Type is hidden
Here is post about this problem: http://social.msdn.microsoft.com/Forums/sharepoint/en-US/93679b02-bfa9-43c2-94ad-ec45191cd478/createtask-method-how-to-create-a-task-based-on-a-custom-content-type
Hope that helped...
Monday, July 15, 2013
Infopath: Get related list item ID from Related Content field
Hi everyone,
There is a simple way how to get related list item ID from Related Content field. Inside Related Content field is stored URL to the related item (in the case of the task). The URL should similar like this: http://site/Lists/listName/DispForm.aspx?ID=33
Then you can use substring-after(WorkflowLink, "=") to get current list item ID
You can find the original thread here: http://social.msdn.microsoft.com/Forums/en-US/59d44915-abd9-484a-8687-926c94cc869b/display-current-item-column-from-list-workflow-in-task-notification-approval-infopath-form
How to use InvokeWebService activity
Hi everybody,
I needed to use InvokeWebService activity and as usual there were some obstacles on the way to do so :)
If you find this error message in the SharePoint log:
System.Net.WebException: The request failed with HTTP status 401: Unauthorized. at System.Workflow.Activities.InvokeWebServiceActivity.Execute(ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(Activity activity, ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime) at System.Workflow.Runtime.Scheduler.Run()
You may need to pass correct credential to your web service.This should be short briefing how to use this activity and pass those credentials to it.
1) Add InvokeWebService activity into your project from the Toolbox :)
2) The add URL to your web service (Choose required method)
3) After that you should see all parameters of the method in the Properties window of the activity
4) Set parameters as needed
If the web service doesn't require any type of permission I believe you can finish here. In my case I needed to pass credential to it.
5) Set Invoking property and add the following method there:
using ApprovalWorkflowProject.projects.server;
I needed to use InvokeWebService activity and as usual there were some obstacles on the way to do so :)
If you find this error message in the SharePoint log:
System.Net.WebException: The request failed with HTTP status 401: Unauthorized. at System.Workflow.Activities.InvokeWebServiceActivity.Execute(ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(Activity activity, ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime) at System.Workflow.Runtime.Scheduler.Run()
You may need to pass correct credential to your web service.This should be short briefing how to use this activity and pass those credentials to it.
1) Add InvokeWebService activity into your project from the Toolbox :)
2) The add URL to your web service (Choose required method)
3) After that you should see all parameters of the method in the Properties window of the activity
4) Set parameters as needed
If the web service doesn't require any type of permission I believe you can finish here. In my case I needed to pass credential to it.
5) Set Invoking property and add the following method there:
using ApprovalWorkflowProject.projects.server;
//Set correct
credentials
Private void Invokingwebservice (object
sender, InvokeWebServiceEventArgs e)
{
YourWebServiceWCF
svc = (YourWebServiceWCF)((InvokeWebServiceEventArgs)e).WebServiceProxy;
svc.Credentials = System.Net.CredentialCache.DefaultCredentials;
}
After you add a InvokeWebService activity the new web reference is created (for more information check this site http://msdn.microsoft.com/en-US/library/d9w023sx(v=vs.80).aspx or look through whole tutorial http://msdn.microsoft.com/en-us/library/t745kdsh(v=vs.80).aspx). You have to add this reference to your project(that's why that using statement) then you will find YourWebServiceWCF class inside the new namespace.
This should be all. If you want more information, here is also post about this topic http://social.msdn.microsoft.com/Forums/sharepoint/en-US/8c782989-649d-4dd9-9749-b919f6e4176b/pass-credentials-using-invokewebservice-activity
Hope that helped...
Approval workflow - This task is currently locked by a running workflow and cannot be edited.
Hello everybody,
I think that if you had developed some approval workflow you would receive an error in the title at least once. You can find a lot of information about the error: "This task is currently locked by a running workflow and cannot be edited.". Here are some links which were quite useful to me:
CreateParallelTaskWithContentType is an activity which creates all tasks and there is logic to do so, but I won't describe it here because it is not related to this topic.
OnTaskCreated activity just sends emails when a new task is assigned.
WhileActivity is a loop which holds task till it is approved.
OnParallelTaskChanged is an activity which controls the previous loop and break it after a task is updated.
CompleteTask is an activity which should complete the current task and in my case has no method.
CodeCompleteAllTask activity is an activity which should complete all tasks if one of the tasks is approved.
Code of the last activity I have written according to articles above and here it is:
I wouldn't recommend doing any type of actions except the approval logic in the replicator activity. Perhaps there is a bug in my code but in my case some activities inside replicator activity were fired more than once even they shouldn't be.
This should be all and I hope this helps somebody with this annoying error :)
Happy coding...
I think that if you had developed some approval workflow you would receive an error in the title at least once. You can find a lot of information about the error: "This task is currently locked by a running workflow and cannot be edited.". Here are some links which were quite useful to me:
The purpose of this post won't be to describe how to solve this error or find the cause of it since there are many posts about this topic already.
I would like to share the approach I have used to achieve my goals. So what my goals were...
1) Typical approval workflow with at least one approver.
2) All tasks should be approved if at least one approver approves the task.
So here is the snapshot of the workflow designer:
OnTaskCreated activity just sends emails when a new task is assigned.
WhileActivity is a loop which holds task till it is approved.
OnParallelTaskChanged is an activity which controls the previous loop and break it after a task is updated.
CompleteTask is an activity which should complete the current task and in my case has no method.
CodeCompleteAllTask activity is an activity which should complete all tasks if one of the tasks is approved.
Code of the last activity I have written according to articles above and here it is:
//Email body
string
emailBody = string.Empty;
//Email
receiver
SPFieldUserValue
recieverValue;
foreach
(SPWorkflowTask task in this.workflowProperties.Workflow.Tasks)
{
if
(task[SPBuiltInFieldId.TaskStatus].ToString()
!= SPResource.GetString(new CultureInfo((int)task.Web.Language, false),
"WorkflowTaskStatusComplete", new object[0]))
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
//Send email notification about rejected task
recieverValue = (SPFieldUserValue)task.Fields[SPBuiltInFieldId.AssignedTo].GetFieldValue((String)task[SPBuiltInFieldId.AssignedTo]);
receiverCompleteAllAssociatedTasks = recieverValue.User;
emailBody += "some text <br />";
sendMail(receiverCompleteAllAssociatedTasks.Email, "Your reply is no longer needed.",
emailBody, true, true);
emailBody = string.Empty;
//Set task as completed
bool allowUnsafeUpdates =
task.Web.AllowUnsafeUpdates;
task.Web.AllowUnsafeUpdates =
true;
task["ApproveStatus"] = "Rejected";
Hashtable data = new
Hashtable();
data[SPBuiltInFieldId.Completed] = "TRUE";
data[SPBuiltInFieldId.PercentComplete] = 1;
data["FormData"] = "Completed";
data["TaskStatus"] = "Approved";
data["Reviewed"] = "Yes";
data["SendSignOffEmail"] = "Yes";
data[SPBuiltInFieldId.TaskStatus] = SPResource.GetString(new
CultureInfo((int)task.Web.Language,
false), "WorkflowTaskStatusComplete",
new object[0]);
bool succed = SPWorkflowTask.AlterTask((task
as SPListItem),
data, false);
if (!succed)
sendMail("", "Error
/ completeAllAssociatedTasks()-AlterTask", "Error
occured at EmployeeID: " + this.workflowProperties.Item["EmployeeID"], false,
false);
//No need to use task.Web.Update() or task.SystemUpdate(),
it is already involved in AlterTask method;
//Set AllowUnsafeUpdates to the original value
task.Web.AllowUnsafeUpdates = allowUnsafeUpdates;
});
}
}
receiverCompleteAllAssociatedTasks = null;
I wouldn't recommend doing any type of actions except the approval logic in the replicator activity. Perhaps there is a bug in my code but in my case some activities inside replicator activity were fired more than once even they shouldn't be.
This should be all and I hope this helps somebody with this annoying error :)
Happy coding...
Monday, July 1, 2013
Successful way to debug SP app using Visual studio 2012 with SharePoint 365
I am quite a new at SharePoint app developing, but recently I needed to deploy and debug App for SharePoint 2013. When I created a new project everything worked fine. I did have a problem though when I wanted to run a project which has been sent to me. I hit the run button then I received this error message: Workflow debugging prerequisites failed to complete. Would you like to disable workflow debugging in order to debug other parts of this project? Workflows will still be installed but will not have debugging support.
It is certain I don't want that, and when I rejected disabling debugging I received this warning and error:
Warning: Microsoft.VisualStudio.SharePoint.SharePointConfigurator.exe could not authenticate successfully to SharePoint to provision workflow debugging prerequisites.
Error: Error occurred in deployment step 'Install app for SharePoint': Deployment was cancelled.
As it turned out it wasn't any technical problem, but just my misunderstanding of handling SharePoint apps (which could be as I think also a problem for other people).
Where the problem is:
You can easily find out that SharePoint apps don't use WSP file but app file. I would expect that this app file is automatically created whenever the Start button is hit (This is the approach which worked fine with WSP files). But I was wrong and you have to create app file manually before you hit the start button. This isn't anything sophisticated, you just right click on your application in Solution Explorer and then click on Publish.. option.
This solved my problem just fine and if I am wrong about something, please let me know. As I said, I am really newbie at SharePont 365 development.
Thanks for reading ;)
It is certain I don't want that, and when I rejected disabling debugging I received this warning and error:
Warning: Microsoft.VisualStudio.SharePoint.SharePointConfigurator.exe could not authenticate successfully to SharePoint to provision workflow debugging prerequisites.
Error: Error occurred in deployment step 'Install app for SharePoint': Deployment was cancelled.
As it turned out it wasn't any technical problem, but just my misunderstanding of handling SharePoint apps (which could be as I think also a problem for other people).
Where the problem is:
You can easily find out that SharePoint apps don't use WSP file but app file. I would expect that this app file is automatically created whenever the Start button is hit (This is the approach which worked fine with WSP files). But I was wrong and you have to create app file manually before you hit the start button. This isn't anything sophisticated, you just right click on your application in Solution Explorer and then click on Publish.. option.
This solved my problem just fine and if I am wrong about something, please let me know. As I said, I am really newbie at SharePont 365 development.
Thanks for reading ;)
Subscribe to:
Posts (Atom)