Discussion

How to pull value from clipboard in Java step

I have a rule-edit-validate rule where I am working on the Java source. I basically want to get the value of a property called EffectiveDate. I see it on the clipboard under UserPages, then pyWorkPage. I need that value to test whether a specific planID should be allowed or not. Here is the code I have right now. [code]if ((.EffectiveDate.substring(7,8) == "01") && (theValue.toString() = "288")) { return false; } return true;[/code] It needs to check if the effective date selected is the 1st day of the month or not, and if a specific planID is selected. The property passed into this rule-edit-validate rule is a property called .planID What am I doing wrong here?

***Updated by moderator: Marissa to close post***
This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.

Comments

Keep up to date on this post and subscribe to comments

Pega
March 3, 2009 - 11:53am

In java, property references don't automatically resolve like they do in an expression field in a form.

Try looking at using the PublicAPI interface, with code similar to:

if ((tools.findPage("pyWorkPage").getString(".EffectiveDate").substring(7,8) == "01") && (theValue.toString() = "288"))
.....

March 3, 2009 - 12:43pm

After trying

[code]if ((theValue.toString() = "288") && (tools.findPage("pyWorkPage").getString(".EffectiveDate").substring(7,8) == "01"))

{
return false;
}
return true;[/code]

I get the following error

Test compilation failed: ----------
1. ERROR in file://runtime:/PRGenJava/Rule_Edit_Validate_ValidPlan_20090303T144918_476_GMT.java
(at line 41)
if ((theValue.toString() = "288") && (tools.findPage("pyWorkPage").getString(".EffectiveDate").substring(7,8) == "01"))
^^^^^^^^^^^^^^^^^^^
The left-hand side of an assignment must be a variable
----------
1 problem (1 error)

Pega
March 3, 2009 - 4:30pm

Looks like a java compilation problem: Did you try == instead of =?

March 4, 2009 - 4:40am

Its error because you are assigning the value 288 not comparing. if you change = to== it will work fine.

March 6, 2009 - 2:52pm

ok that works.

Now how can i used the above logic using the expression builder for a when rule?

There are so many libraries there amd i'm not sure how to make this work using the expression builder

March 8, 2009 - 8:01pm

You can use @substring(string,length) directly inside a when rule and the string comparison too. (@(Pega-RULES:ExpressionEvaluators).compareTwoStrings(Page.Property, "EQUALS", "Value")

March 9, 2009 - 11:47am

Thanks for that. It is looking good now.

Let say I am using the expression builder to see if a date is more than 30 days in the past. How could I do that?