Compare numerical value with comparison operator

  • 29 January 2008
  • 1 reply
  • 1 view

Badge +13

[{K2.ProcessInstance.XmlFields("FormData/mstns:WorkItemData/mstns:Transactions/mstns:Transaction/mstns:TotalOverdraftAmt").Value}]

Comparison Operator  >

Second Variable  0

?"0" > "0.00"
False

?"0.00" > "0"
True

 Based on the code generated it treats it as string.   So is there a way to compare it numerically without having to modify and use code?

If firstVariable.ToString.ToUpper > secondVariable.ToString.ToUpper Then
        Return True
 

Even if the 2nd variable is defined as a process data of type integer, it still coverts to string and compare it as string. 


1 reply

Badge +9

Peter,


I am not seeing this behavior.  If i have an element of type integer within an XML schema  in a K2 XML Field I am able to use it as line rule without issue.


For example I have a infopath K2 process that has a K2 XML field with the following structure (for purpose of this listing, I've stripped out much of the non-essential elements the infopath xml doc):


   <xs:complexType>
    <xs:sequence>
     <xs:element name="my:FirstName" type="xs:string" minOccurs="0" />
     <xs:element name="my:LastName" type="xs:string" minOccurs="0" />
     <xs:element name="my:Request" type="xs:string" minOccurs="0" />
     <xs:element name="my:Approved" type="xs:string" minOccurs="0" />
     <xs:element name="my:AgeAsInt" type="xs:integer" minOccurs="0" />
    </xs:sequence>
   </xs:complexType>


Notice, my last element "AgeAsInt" is of datatype integer.  Within the Process, I also have a K2 Process Data Field called 'AgeThreshold" of type integer with a default value of 5.


Within the K2 process I create a line that contains a line rule:


1. "AgeAsInt" >= [{K2.ProcessInstance.DataFields("AgeThreshold").Value}]


When I run the process and enter an AgeAsInt and 8, the line rule evaluates correctly (8 > 5).  If i generate the code for this line I see the code generates as:




private bool Func1(ref LineRuleContext K2) {


 string strTemp1;
 string strTemp2;
 string strTempLD;
 object firstVariable;
 object secondVariable;
 object LogicalData;


 bool blnFirstNode;
 System.Xml.XmlNodeList objNodeList;
 strTemp1 = K2.ProcessInstance.XmlFields["K2InfoPathSchema"].Value;
 firstVariable = SourceCode.K2Utilities.XMLFieldMod.GetXMLValue(strTemp1, "my:myFields/my:AgeAsInt");



 secondVariable = K2.ProcessInstance.DataFields["AgeThreshold"].Value;



 if (System.Convert.ToInt32(firstVariable) > System.Convert.ToInt32(secondVariable))
  return true;
 else
  return false;
}
 


Notice that Ints are being used, not strings.


Is it possible that the element you are pointing to (I believe 'TotalOverdraftAmt') is of type text? 


 


 

Reply