problem reading extendedproperties with getData()

Jun 17, 2009 at 5:25 PM
Edited Jun 17, 2009 at 7:15 PM

Hi, thank you for sharing this great work!

I need some help starting using the downloaded code (release 1.1) with VS2005. two problems

1) The Sample project: error in reading extended property "Instructions" in TaskOneForm.ascx

  •  Installed compiled and Deployed. all ok
  • Started a workflow instance: the workflow executes
    private void CreateTaskOne_Invoking(object sender, EventArgs e)
    { 
	...
      activity.TaskProperties.ExtendedProperties["Instructions"] = _configData.Instructions;
    }
  • activity.TaskProperties.ExtendedProperties contains (correct)
  • ?activity.TaskProperties.ExtendedProperties
    Count = 4
        [{cd21b4c2-6841-4f9e-a23a-738a65f99889}]: {20/06/2009 18.35.41}
        [{8d96aa48-9dff-46cf-8538-84c747ffa877}]: 0
        ["Instructions"]: "ppppppppppppppppppp"
        [{53101f38-dd2e-458c-b245-0c236cc13d1a}]: "lurano\\rob"
  • Tried to update the task one: Opening the TaskOneForm.ascx, the workflow executes
  •  protected override void LoadData(bool isInitialLoad)
        {
            if (isInitialLoad)
            {            
                	TaskData data = GetData();

    try {

    instructionsField.Text = data[

    "Instructions"] as String;

    }

    catch (Exception ex) {

    instructionsField.Text = ex.Message;

    }

    } }
  • the data collection doesn't contains "Instructions", so data["Instructions"] will fail
  • Saving the TaskOneForm.ascx, saveData() executes and the task completes correcty , etc
  • WHAT I'M MISSING?

    2) The TPG.SharePoint.Workflow project: Error in loading project.

    • NOTE: THIS PROBLEM WAS SOLVED PLS SEE MY REPLY ABOVE

    thank you for help.

    Roberto

  • Jun 17, 2009 at 7:03 PM
    Edited Jun 17, 2009 at 7:17 PM

    My second problem was resolved.

    Now the TPG.SharePoint.Workflow project loaded, compiled, deployed.

    The Source project references the TPG.SharePoint.Workflow. I'm able to follow stack call in TPG.SharePoint.Workflow  now! (Hope this will help in debugging my first problem)

    These are the steps used to "downgrade" the TPG.SharePoint.Workflow project to VS2005:

    1. errors in TPG.SharePoint.Workflow.csproj
      • changed  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />  into <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
      • changed <AssemblyOriginatorKeyFile>..\Signing\Key.snk</AssemblyOriginatorKeyFile> into <AssemblyOriginatorKeyFile>.\Key.snk</AssemblyOriginatorKeyFile>
      • removed the following rows
        • <Compile Include="Activities\Design\OnWorkflowActivatedDesigner.cs" />
        • <Compile Include="Activities\OnWorkflowActivated.cs">
    2. errors in customBuild.targets: changed following rows (internationalization)
      • <SharePointPath>"%CommonProgramFiles%\Microsoft Shared\web server extensions\12"</SharePointPath>
      • <GacUtilPath>"%ProgramFiles%\Microsoft Visual Studio 8\SDK\v2.0\bin\gacutil.exe"</GacUtilPath>
      • <StsAdmPath>"%CommonProgramFiles%\Microsoft Shared\web server extensions\12\bin\stsadm.exe"</StsAdmPath>
    3. Errors in *.cs:
      • replaced all C#3.0 "implicit" code into "explicit"
    4. errors in Skipverification.bat:
      • changed into %SNEXE% -Vr .\bin\debug\x86\TPG.SharePoint.Workflow.dll
    Jun 18, 2009 at 9:04 AM
    Edited Jun 18, 2009 at 9:59 AM

    About my first problem

    1) In the TaskData.getProperty() method, the "return value.Value" instruction throws a too generic "invalid reference" error if the key not exists. I suggest this slight variation (banal but useful)

    object GetProperty(object key)
            {
                DataItem value = null;
                if (_contentTypePropertyKeys.ContainsKey(key))
                {
                    SPField field = _contentTypePropertyKeys[key];
                    value = _taskData[field.Id];
                }
                else if (_taskData.ContainsKey(key))
                {
                    value = _taskData[key];
                }
               else {throw new SPException("key not exists");    }
                return value.Value;
            }

     2) in method TaskPage.GetWorkflowTaskData(), the ListItem do not have ExtendedProperties
            protected TaskData GetWorkflowTaskData()
            {
                TaskData taskData = new TaskData(ListItem,SPWorkflowTask.GetExtendedPropertiesAsHashtable(ListItem));
    

     3) BUT, when the ListItem was created in Sample.Workflow.CreateTaskOne_Invoking() the extended property was there!

       private void CreateTaskOne_Invoking(object sender, EventArgs e)
        {
          TaskId = Guid.NewGuid();
          CreateTask activity = sender as CreateTask;
    
          activity.TaskProperties = new SPWorkflowTaskProperties();
          activity.TaskProperties.AssignedTo = _configData.Level1Approver;
          activity.TaskProperties.TaskType = 0;
          activity.TaskProperties.DueDate = DateTime.Now.AddDays(3);
          activity.TaskProperties.ExtendedProperties["Instructions"] = _configData.Instructions;
          activity.TaskProperties.Title = "Perform Task One";
        }
    
    4) I've tried also to reinstall only the Sample code and the TPG_SharePoint_Workflow_1_0_0.wsp: the problem is always there.
    I'm sure I'm missing something ... ?
    thank you for any suggestion
    Roberto
    Jun 24, 2009 at 6:39 PM

    I've made a more sistematic test. Here my conclusions:

    1) during workflow task creation i set three fields:

    	taskProperties = New SPWorkflowTaskProperties
    	'a standard field
    	taskProperties .Description = String.Format("L'utente {0} chiede l'esecuzione dell'attività: {1} sulla segnalazione: {2}", userBefore, descrizioneTask, itemFullName)
    	'a custom field 
    	taskProperties .ExtendedProperties("ParCommessa") = "ASSISTENZA"
    	'an extended property 
    	taskProperties .ExtendedProperties("Istruzioni") = "COMMENTS"
    
    2) during task modification, in LoadData(), I read the fields using various techniques:
    	Dim data As TaskData = GetData()
    	Dim taskItem As SPListItem = SPContext.Current.ListItem            
    	Dim s As String = ""
    	s += String.Format("a)Accessing a standard field <BR/> me.body()={0}, data(SPBuiltInFieldId.Body)={1}, taskItem(SPBuiltInFieldId.Body)={2}<BR/>", _
    		Me.Body, data(SPBuiltInFieldId.Body), taskItem(SPBuiltInFieldId.Body))	
    	s += String.Format("b)Accessing a custom field <BR/> data(""ParCommessa"")={1}, taskItem(""ParCommessa"")={2}<BR/>" ,_
    		data("ParCommessa").ToString, taskItem("ParCommessa"))
    	s += String.Format("c)Accessing an extended property <BR/> data(""Istruzioni"")={1}, taskItem(""Istruzioni"")={2}<BR/>", _
    		data("Istruzioni").ToString, taskItem("Istruzioni"))
    
    
    3) Conclusions:
    • I can access a standard field either using a TPG.SharePoint.Workflow.TaskControl property, or accessing the taskData Collection or the TaskItem.Fields collection
    • I can access a custom field using TaskItem.Fields collection BUT NOT using a taskData Collection (why? this is the same question of my previous post)
    • I can access an extended property using taskData Collection BUT NOT using TaskItem.Fields collection (an this is correct)
    It seems the taskData collection it's only useful for accessing extended Properties, but the comments in the TPG.SharePoint.Workflow.TaskData class says otherwise. 
    So ... anyone can suggest me what I'm missing?
    thank you very much 
    Rob
    Coordinator
    Jun 25, 2009 at 5:50 PM
    Here's the deal. The TaskData class serves as an abstraction for both properties defined in your task content-type and in the extended properties collection. It also provides you with some protection to what you can access. Normal task fields can be accessed using the internal name and field ID (GUID).

    You can create a workflow task using two approaches.

    A. You do not define a custom content-type

    In this case you use the extended properties as a generic name / value bag. The TaskData class will automatically set AllowExtendedProperties to true so you can use names that are not matched to the task list item's fields.

    B You define a custom content-type for your task (and you use the CreateTaskWithContentType activity)

    In this case each value you want to persist is stored as a field in the task list item. The TaskData class automatically sets AllowExtendedProperties to false so you can only use field internal names or field IDs (you can change AllowExtendedProperties yourself).

    Hope it helps,

    wouter


    ________________________________

    Van: Interah [mailto:notifications@codeplex.com]
    Verzonden: wo 24-6-2009 20:39
    Aan: Wouter van Vugt
    Onderwerp: Re: problem reading extendedproperty in taskData (running Sample code, rel 1.1 on VS2005) [wss3workflow:59841]



    From: Interah

    I've made a more sistematic test. Here my conclusions:

    1) during workflow task creation i set three fields:

    taskProperties = New SPWorkflowTaskProperties
    'a standard field
    taskProperties .Description = String.Format("L'utente {0} chiede l'esecuzione dell'attività: {1} sulla segnalazione: {2}", userBefore, descrizioneTask, itemFullName)
    'a custom field
    taskProperties .ExtendedProperties("ParCommessa") = "ASSISTENZA"
    'an extended property
    taskProperties .ExtendedProperties("Istruzioni") = "COMMENTS"
    2) during task modification, in LoadData(), I read the fields using various techniques:
    Dim data As TaskData = GetData()
    Dim taskItem As SPListItem = SPContext.Current.ListItem
    Dim s As String = ""
    s += String.Format("a)Accessing a standard field
    me.body()={0}, data(SPBuiltInFieldId.Body)={1}, taskItem(SPBuiltInFieldId.Body)={2}
    ", _
    Me.Body, data(SPBuiltInFieldId.Body), taskItem(SPBuiltInFieldId.Body))
    s += String.Format("b)Accessing a custom field
    data(""ParCommessa"")={1}, taskItem(""ParCommessa"")={2}
    " ,_
    data("ParCommessa").ToString, taskItem("ParCommessa"))
    s += String.Format("c)Accessing an extended property
    data(""Istruzioni"")={1}, taskItem(""Istruzioni"")={2}
    ", _
    data("Istruzioni").ToString, taskItem("Istruzioni"))

    3) Conclusions:



    * I can access a standard field either using a TPG.SharePoint.Workflow.TaskControl property, or accessing the taskData Collection or the TaskItem.Fields collection
    * I can access a custom field using TaskItem.Fields collection BUT NOT using a taskData Collection (why? this is the same question of my previous post)
    * I can access an extended property using taskData Collection BUT NOT using TaskItem.Fields collection (an this is correct)

    It seems the taskData collection it's only useful for accessing extended Properties, but the comments in the TPG.SharePoint.Workflow.TaskData class says otherwise.
    So ... anyone can suggest me what I'm missing?
    thank you very much
    Rob

    Read the full discussion online <http://wss3workflow.codeplex.com/Thread/View.aspx?ThreadId=59841&ANCHOR#Post205106> .

    To add a post to this discussion, reply to this email ([email removed] <mailto:[email removed]?subject=[wss3workflow:59841]> )

    To start a new discussion for this project, email [email removed]

    You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings <http://www.codeplex.com/site/discussions/project/unsubscribe/wss3workflow> on codePlex.com.

    Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com