Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1461
  • Last Modified:

URI error in a c# sharepoint workflow

Hello... we are trying to develop a custom c# workflow for MOSS 2007.  We have been able to successfully create a task.  Now we are trying to add in an assigned to field that retrieves the value from a person or group field.  We found some code that should allow us to use the created by field and retrieve the user from that.  However we receive a value cannot be null error when we try to debug the workflow.  We are not familiar enough with vis studio workflow development that we have been able to figure out what might be wrong.  
Any assistance will be greatly appreciated.  The error is {"Value cannot be null.\r\nParameter name: uriString"}
Thanks
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;
using Microsoft.Office.Workflow.Utility;
using System.Text.RegularExpressions;
 
 
namespace MSDNTest
{
    public sealed partial class Workflow1 : StateMachineWorkflowActivity
    {
        public Workflow1()
        {
            InitializeComponent();
        }
 
        public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
        public Guid CreateInProgressTask_TaskId1 = default(System.Guid);
        public SPWorkflowTaskProperties CreateInProgressTask_TaskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
     
 
        private void CreateInProgressTask_MethodInvoking(object sender, EventArgs e)
        {
        // Getting the employeesName from the SharePoint List (comes as raw HTML)
        string employeesName = workflowProperties.Item.GetFormattedValue("Created By").ToString();
 
        // Converting it to a UserName string
        employeesName = Regex.Replace(employeesName, @"<(.|\n)*?>", string.Empty);
        
 
        //SPListItem currentitem = workflowProperties.Item;
        //string fieldvalue = currentitem["Manager"].ToString();
        //SPFieldUser manager = (SPFieldUser)currentitem["Manager"];
        //SPFieldUserValue user = (SPFieldUserValue)manager.GetFieldValue(currentitem["Manager"].ToString());
        //SPUser userobject = user.User;
        CreateInProgressTask_TaskId1 = Guid.NewGuid();
        CreateInProgressTask_TaskProperties1.Title = "Finish document changes/updates";
        CreateInProgressTask_TaskProperties1.DueDate = DateTime.Now.AddDays(1.0);
        CreateInProgressTask_TaskProperties1.AssignedTo = employeesName;

Open in new window

0
pattersonr
Asked:
pattersonr
  • 7
  • 5
2 Solutions
 
nmarunCommented:
Try the below method. The method returns a SPUser and you can use the .Name member to get the name of the user.

        private SPUser GetCreatedByUser()
        {
            var CreatedBy =
                new SPFieldUserValue(workflowProperties.Web, workflowProperties.Item["Created By"].ToString());
            return CreatedBy.User;
        }

Open in new window

0
 
pattersonrAuthor Commented:
nmarun...
Thanks for the quick reply.  We are still working through the code you provided.  However, our real aim is to connect to a sharepoint list and retrieve a person/group field from the list.  You can see the commented out code above.  We we resorting to the created by user just to try to understand how the object model worked.
Could you point me in the direction to reference the list field?  The code we had above doesnt work.

Thanks again
0
 
nmarunCommented:
I don't see the difference in the way you are using the user information. You are trying to get the user who created the workflow and then assign it to the 'Assigned To' field. I have modified your code to do the same:

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;
using Microsoft.Office.Workflow.Utility;
using System.Text.RegularExpressions;
 
 
namespace MSDNTest
{
    public sealed partial class Workflow1 : StateMachineWorkflowActivity
    {
        public Workflow1()
        {
            InitializeComponent();
        }
 
        public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
        public Guid CreateInProgressTask_TaskId1 = default(System.Guid);
        public SPWorkflowTaskProperties CreateInProgressTask_TaskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
     
        private SPUser GetCreatedByUser()
        {
            var CreatedBy =
                new SPFieldUserValue(workflowProperties.Web, workflowProperties.Item["Created By"].ToString());
            return CreatedBy.User;
        }
 
        private void CreateInProgressTask_MethodInvoking(object sender, EventArgs e)
        {
        // Getting the employeesName from the SharePoint List (comes as raw HTML)
        SPUser CreatedUser = GetCreatedUser();
 
        //SPListItem currentitem = workflowProperties.Item;
        //string fieldvalue = currentitem["Manager"].ToString();
        //SPFieldUser manager = (SPFieldUser)currentitem["Manager"];
        //SPFieldUserValue user = (SPFieldUserValue)manager.GetFieldValue(currentitem["Manager"].ToString());
        //SPUser userobject = user.User;
        CreateInProgressTask_TaskId1 = Guid.NewGuid();
        CreateInProgressTask_TaskProperties1.Title = "Finish document changes/updates";
        CreateInProgressTask_TaskProperties1.DueDate = DateTime.Now.AddDays(1.0);
        CreateInProgressTask_TaskProperties1.AssignedTo = CreatedUser.Name;

Open in new window

0
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
pattersonrAuthor Commented:
nmarun
Sorry maybe I didnt explain well.  Our eventual goal is not to get the created by user...but to get a field from the list entitled RFC.  The field that we want is the Manager.  Basically, a user fills in a list and selects their manager.  We want a task to be assigned to the manager.  
We only used the created by as a general functionality test.
Could we use your code and change the Created By to Manager?  Would that work?

0
 
pattersonrAuthor Commented:
nmarun
We got your original code pasted in and double checked it with the additional code that you modified.  However on the var CreatedBy statement when the code is debugged...we still get an error saying Value cannot be null.  Is it possible, we dont have something linked correctly in the properties.
As I am sure you can tell we are not too familiar with Sharepoint Development or c# ...
Thanks again for your help.
0
 
nmarunCommented:
How is the Manager field populated? Is this a lookup / user picker / text entry?

If it is a lookup / text entry, then what you are using should work. If it is a user picker, then try the GetCreatedByUser() method.
0
 
pattersonrAuthor Commented:
The Manager field is a user picker.. we changed the field name in the method to be Manager.  However we still receive a break when debugging due to the null value
0
 
nmarunCommented:
Can you please post your updated code?
0
 
pattersonrAuthor Commented:
We have gotten the null error on nearly everything we have tried in this task list.  The task creation only runs if we just let it create the task without trying to get any values from the original list.
I am wondering if somehow it isnt referencing the original list correctly.....
Just a theory since I really dont know what I am doing.
Thanks again for the help.
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;
using Microsoft.Office.Workflow.Utility;
//using System.Text.RegularExpressions;
 
 
namespace MSDNTest
{
    public sealed partial class Workflow1 : StateMachineWorkflowActivity
    {
        public Workflow1()
        {
            InitializeComponent();
        }
 
        public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
        public Guid CreateInProgressTask_TaskId1 = default(System.Guid);
        public SPWorkflowTaskProperties CreateInProgressTask_TaskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
       
    
         private SPUser GetCreatedByUser()
        {
            var CreatedBy = new SPFieldUserValue(workflowProperties.Web, workflowProperties.Item["Manager"].ToString());
            return CreatedBy.User;
        }
 
        private void CreateInProgressTask_MethodInvoking(object sender, EventArgs e)
        {
            SPUser CreatedUser = GetCreatedByUser();
         // Getting the employeesName from the SharePoint List (comes as raw HTML)
        //string employeesName = workflowProperties.Item["Created By"].ToString();// .GetFormattedValue("Created By").ToString();
 
        // Converting it to a UserName string
        //employeesName = Regex.Replace(employeesName, @"<(.|\n)*?>", string.Empty);
        //string employeesName = "moss/mossinstall";
       
            string employeeName = CreatedUser.Name;
 
        //SPListItem currentitem = workflowProperties.Item;
        //string fieldvalue = currentitem["Manager"].ToString();
        //SPFieldUser manager = (SPFieldUser)currentitem["Manager"];
        //SPFieldUserValue user = (SPFieldUserValue)manager.GetFieldValue(currentitem["Manager"].ToString());
        //SPUser userobject = user.User;
        CreateInProgressTask_TaskId1 = Guid.NewGuid();
        CreateInProgressTask_TaskProperties1.Title = "Finish document changes/updates";
        CreateInProgressTask_TaskProperties1.DueDate = DateTime.Now.AddDays(1.0);
        CreateInProgressTask_TaskProperties1.AssignedTo = employeeName;          
        
        }

Open in new window

0
 
nmarunCommented:
I've never used a StateMachineWorkflowActivity, all of my workflows are Sequential. Is there are reason why you need StateMachine system?
http://msdn.microsoft.com/en-us/library/cc768563.aspx


Also have a look at this:
http://msdn.microsoft.com/en-us/library/cc627284.aspx
0
 
pattersonrAuthor Commented:
nmarun
Unfortunately this is the start of a very large workflow.  The general design will be to pass a document through several multistep approval processes.  The document will have states for approval, rejection, draft, cancellation, etc.  By far the most efficient design is a state approval.
Bascially, there are a number of steps and the workflow can loop around through all of the different approval steps making a sequential workflow pretty difficult.

I hope that helps explain.
Thanks for your continued help.

0
 
pattersonrAuthor Commented:
nmarun
After some further examination I realized that I had some steps out of sequence.  At the point that I was looking for some of the workflowproperties.  I had not yet run the onworkflowactivated step.  after I got this properly rearranged. Then all of the other methods could properly reference the task items.

Thank you for the help though.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now