none
Assign a New Guid to a Variable

    Question

  • I have a flowchart and on step 1 I put as assign statement.  I want to generate a new GUID for a variable scoped to the flowchart...then continue on from there.

    However the statement doesn't seem to actually generate a GUID...

    Variable: ApprovalID
    Assign: ApprovalID = Guid.NewGuid()

    ApprovalID is definatly of type GUID, and the scope is right...there are no exceptions and it compiles fine...but it never gives me a new GUID

    Is it a VB syntax thing?  This is how it should work, no?

    Friday, May 28, 2010 7:59 PM

Answers

  • You are doing it exactly right. How do you know there is no value going into the ApprovalId variable? Later in the workflow when you try to use it, is it blank/null?

    I created a new workflow, put a sequence on it, gave it a variable called ApprovalId of type Guid (you know you can also initialize it to a new Guid in the Variables windows), then added an Assign followed by a WriteLine.

    It should work, you have it just right.

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

     

    <Activity mc:Ignorable="sap" x:Class="AssignTest.Workflow1" sap:VirtualizedContainerService.HintSize="304,323" mva:VisualBasic.Settings="Assembly references and imported namespaces for internal implementation" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core" xmlns:s4="clr-namespace:System;assembly=System.ServiceModel" xmlns:sa="clr-namespace:System.Activities;assembly=System.Activities" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:st="clr-namespace:System.Text;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
     <Sequence sad:XamlDebuggerXmlReader.FileName="C:\WFProjects\AssignTest\Workflow1.xaml" sap:VirtualizedContainerService.HintSize="264,283">
      <Sequence.Variables>
       <Variable x:TypeArguments="s:Guid" Name="ApprovalId" />
      </Sequence.Variables>
      <sap:WorkflowViewStateService.ViewState>
       <scg3:Dictionary x:TypeArguments="x:String, x:Object">
        <x:Boolean x:Key="IsExpanded">True</x:Boolean>
       </scg3:Dictionary>
      </sap:WorkflowViewStateService.ViewState>
      <Assign sap:VirtualizedContainerService.HintSize="242,58">
       <Assign.To>
        <OutArgument x:TypeArguments="s:Guid">[ApprovalId]</OutArgument>
       </Assign.To>
       <Assign.Value>
        <InArgument x:TypeArguments="s:Guid">[Guid.NewGuid()]</InArgument>
       </Assign.Value>
      </Assign>
      <WriteLine sap:VirtualizedContainerService.HintSize="242,61" Text="[ApprovalId.ToString()]" />
     </Sequence>
    </Activity>
    Friday, May 28, 2010 9:14 PM

All replies

  • You are doing it exactly right. How do you know there is no value going into the ApprovalId variable? Later in the workflow when you try to use it, is it blank/null?

    I created a new workflow, put a sequence on it, gave it a variable called ApprovalId of type Guid (you know you can also initialize it to a new Guid in the Variables windows), then added an Assign followed by a WriteLine.

    It should work, you have it just right.

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

     

    <Activity mc:Ignorable="sap" x:Class="AssignTest.Workflow1" sap:VirtualizedContainerService.HintSize="304,323" mva:VisualBasic.Settings="Assembly references and imported namespaces for internal implementation" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core" xmlns:s4="clr-namespace:System;assembly=System.ServiceModel" xmlns:sa="clr-namespace:System.Activities;assembly=System.Activities" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:st="clr-namespace:System.Text;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
     <Sequence sad:XamlDebuggerXmlReader.FileName="C:\WFProjects\AssignTest\Workflow1.xaml" sap:VirtualizedContainerService.HintSize="264,283">
      <Sequence.Variables>
       <Variable x:TypeArguments="s:Guid" Name="ApprovalId" />
      </Sequence.Variables>
      <sap:WorkflowViewStateService.ViewState>
       <scg3:Dictionary x:TypeArguments="x:String, x:Object">
        <x:Boolean x:Key="IsExpanded">True</x:Boolean>
       </scg3:Dictionary>
      </sap:WorkflowViewStateService.ViewState>
      <Assign sap:VirtualizedContainerService.HintSize="242,58">
       <Assign.To>
        <OutArgument x:TypeArguments="s:Guid">[ApprovalId]</OutArgument>
       </Assign.To>
       <Assign.Value>
        <InArgument x:TypeArguments="s:Guid">[Guid.NewGuid()]</InArgument>
       </Assign.Value>
      </Assign>
      <WriteLine sap:VirtualizedContainerService.HintSize="242,61" Text="[ApprovalId.ToString()]" />
     </Sequence>
    </Activity>
    Friday, May 28, 2010 9:14 PM
  • I had breakpoints going to see the data...and the step after tries to create an object based on that GUID, so it threw an exception on NULL

    So well I don't know what happened, but now it's working...I didn't change any code, just came back from cutting the grass..and the first time I ran it I saw it create the GUID, but on the next step it was null again (no transition activities, and the activity after the assign hadn't even been run yet).  So I ran it again directly after that and everything ran fine

    No idea why...never changed any code...

    Friday, May 28, 2010 10:19 PM