| | | Supreme Being
       
Group: Forum Members Last Login: Sunday, August 22, 2010 Posts: 11, Visits: 43 |
| I'd like to use decision action based on the existence of a Workflow instance variable. If I add a rule like "Variable.MyVariableName Contains Data", I get an error that looks like:
**** Error while executing GetProcessedValue : System.Reflection.TargetInvocationException: System.NullReferenceException:
Looking at the generated code, it uses: _context.Variables["MyVariableName"].Value
which would cause a NullReferenceException if _context.Variables["MyVariableName"] is null. Is there another way to determine if MyVariableName is null?
Thanks |
| | | | Senior Member
       
Group: Forum Members Last Login: Friday, January 16, 2009 Posts: 8, Visits: 21 |
| | Hi Tonyyng, You can use Expression Editor in Decision action to determine whether the variable (MyVariableName) is null or not. Use the below sample code in Decision action's Expression editor. Find attached the document (DecisionAction.doc) as well as the workflow xml (NullVariable.zip) for your referecce. (Variable.MyVar == null) ? true: false ReturnType+= Sysetm.Boolean Let us know the status after performing this. Regards, Anil
|
| | | | Supreme Being
       
Group: Forum Members Last Login: Sunday, August 22, 2010 Posts: 11, Visits: 43 |
| Thanks. That worked fine.
The expression can be simplified from:
(Variable.MyVariable == null) ? true:false to Variable.MyVariable == null |
| | | | Supreme Being
       
Group: Forum Members Last Login: Monday, November 21, 2011 Posts: 11, Visits: 66 |
| | Hi I'd like to raise an issue with this scenario,I have tried this solution in BPM.NET 2006 and it works fine, however, when using a task based variable, it does not work, e.g. (Variable.^UI-SingleTaskRespondingUser==null)?true:false On clicking OK, the following error appears: | c:\WINDOWS\Temp\_l173fja.0.cs(11,9) : error CS1525: Invalid expression term '==' | | | | c:\WINDOWS\Temp\_l173fja.0.cs(11,11) : error CS1026: ) expected | | | | c:\WINDOWS\Temp\_l173fja.0.cs(11,15) : error CS1002: ; expected | | | | c:\WINDOWS\Temp\_l173fja.0.cs(11,15) : error CS1525: Invalid expression term ')' |
Code generated is: using System; using System.Text; using Workflow.NET; namespace Samplenamespacec161bc3071584a52b349f3e4c14100fa { public class Sampleb508fd62ffdd42d397030bdaa6fe35df {
public object SampleMethodbff44cf2a4b7434db7c9960282fd0b41(Workflow.NET.Engine.Context _context) { return (==null)?true:false ; }
} }
In the code it is dropping the variable, should this work? Thanks Jon |
| | | | Supreme Being
       
Group: Forum Members Last Login: Thursday, February 10, 2011 Posts: 28, Visits: 47 |
| Hi Jon, You may try using the individual property of the respective variable as mentioned below Variables.^CandidateApprovalRespondingUser.UserName==null?true:false This should work. Regards Saravanan |
| | | | Supreme Being
       
Group: Forum Members Last Login: Monday, November 21, 2011 Posts: 11, Visits: 66 |
| ','165');" onclick="if_openMenu('_ctl1__ctl0_ctlTopic__ctl0_ctlPanelBar_ctlTopicsRepeater__ctl5_smAuthorName','_ctl1__ctl0_ctlTopic__ctl0_ctlPanelBar_ctlTopicsRepeater__ctl5_smAuthorName_DivLayer','','165');" 100%px;? width:>Hi Saravanan | ','165');" onclick="if_openMenu('_ctl1__ctl0_ctlTopic__ctl0_ctlPanelBar_ctlTopicsRepeater__ctl5_smAuthorName','_ctl1__ctl0_ctlTopic__ctl0_ctlPanelBar_ctlTopicsRepeater__ctl5_smAuthorName_DivLayer','','165');" 100%px;? width:> | ','165');" onclick="if_openMenu('_ctl1__ctl0_ctlTopic__ctl0_ctlPanelBar_ctlTopicsRepeater__ctl5_smAuthorName','_ctl1__ctl0_ctlTopic__ctl0_ctlPanelBar_ctlTopicsRepeater__ctl5_smAuthorName_DivLayer','','165');" 100%px;? width:>Thanks for your response, this allowed me to set up the decision task, however, the workflow always finishes at the decision task with no output, so if I check for Null and if it is the output should be NULL, else NOTNULL, but neither output is generated, it just stops. The error logged is as below. |