Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
Hi, I have to decide my workflow path depending on an attribute type, which is having a list of values, Each value will take a separate workflow after choosing it.
I am tried to execute the below code but some how not succesful.
For Routing Two options succesfully executed, while i am using the values in place of String_value its not working.
Soft Attribute Name = CustomerGroup, Dropdown values are HERO/FORD.
if (primaryBusinessObject != null)
{
try
{
com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(primaryBusinessObject,null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
obj.load("CustomerGroup");
java.lang.String string_value = (java.lang.String) obj.get("CustomerGroup");
System.out.println("Soft attibute value : " + string_value);
if ( string_value == "HERO" )
{
result = "Route1";
}
else
if( string_value == "FORD" )
{
result="Route3";
}
else
result="Route2";
}
catch ( Exception e )
{
e.printStackTrace();
}
},
Below code executed succesfully,
Soft Attribute Name = CustomerGroup, Dropdown values are HERO/FORD.
if (primaryBusinessObject != null)
{
try
{
com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(primaryBusinessObject,null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
obj.load("CustomerGroup");
java.lang.String string_value = (java.lang.String) obj.get("CustomerGroup");
System.out.println("Soft attibute value : " + string_value);
if ( string_value !=null)
{
result = "Route1";
}
else
result="Route2";
}
catch ( Exception e )
{
e.printStackTrace();
}
}
Thanks in advance.
Try .equals() or equalsIgnoreCase() to compare the values to String values and check if it helps.
string_value.equals("FORD"); string_value.equalsIgnoreCase("FORD");
Thanks
Shreyas
Hi Sheyas,
Thanks for your reply, Its giving syntax error.
Thanks.
Can you share what syntax error your getting ??
Thanks,
Shreyas
Please find the below error,
Checking Syntax...
C:\ptc\Windchill_10.2\Windchill\temp\WfExpression99308.java:43: error: illegal start of expression
)
^
C:\ptc\Windchill_10.2\Windchill\temp\WfExpression99308.java:48: error: 'else' without 'if'
else if( string_value.equals("FORD"));
^
C:\ptc\Windchill_10.2\Windchill\temp\WfExpression99308.java:53: error: 'else' without 'if'
else
^
3 errors
Syntax check complete
Thanks
Mahesh
Try below expression.
if (primaryBusinessObject != null)
{
try
{
com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(primaryBusinessObject,null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
obj.load("CustomerGroup");
java.lang.String string_value = (java.lang.String) obj.get("CustomerGroup");
System.out.println("Soft attibute value : " + string_value);
if ( string_value.equals("HERO") )
{
result = "Route1";
}
else
if( string_value.equals("FORD") )
{
result="Route3";
}
else
result="Route2";
}
catch ( Exception e )
{
e.printStackTrace();
}
}
Now, there is no syntax error, but Default "Route2" option is executing. If choose IF condition as null, throwing an error. ATTENSION: null
Thanks
Mahesh
Remember that java is case sensitive, so the case statement string_value.equals("HERO") means the attribute value shas to be HERO and not Hero etc for it to work.
You can also use equalsIgnoreCase() or if(compareToIgnoreCase("HERO") == 0) ....