Posted: 3 Jun 2016 5:30 EDT Last activity: 3 Jun 2016 12:38 EDT
Can we access local variables of an activity in a called data transform ?
there is a final activity that calls a data transform which is an extension point. I want to access the local variables of the calling activity in my data transform to do some processing ... Is there any way to do that ?
End requirement :-
On upload of an image in an RTE (rich text editor), I want to check the size of the inserted image, the moment it is uploaded. There is a OOTB final activity that is going to upload the image file and it being final, I cannot modify it. It calls a data transform that can be used to set an message to user.
the problem is that, then these need to be passed as parameters in parameter page. but wont i be able to pass local variables as is ? because the calling activity here is a final pega ootb activity and i cant modify it.
Posted: 4 years ago
Updated: 4 years ago
Posted: 3 Jun 2016 12:14 EDT Updated: 3 Jun 2016 12:20 EDT
If I understand what you want to do here: which is use a Data Transform to set local values in a calling Activity - I don't think there is any way that you could achieve currently.
In your case: I think the only solution is make a copy of the Final Activity in question (effectively re-implementing the Activity in a way that suits your requirements): or logging a request to GCS - so see whether this Activity could be 'de-finalized' (if that is feasible and a doesn't have other consequences down the line somehow).
I could be wrong in this : but here's what I tried: and my findings to show why I came to this conclusion:
I tried to create a simple Data Transform that sets a Local scope variable - the Designer Studio prevents me from doing this:
Furthermore the 'Parameters' Tab for a Data Transform doesn't let me define any Local scoped values (unlike Activities):
Compare that to an Activity,
So on the Params tab; we can define a Local scoped variable : 'a' of type 'String':
And on the Steps tab we then use a Property-Set step to set the value of 'Local.a':
This saves without issue - and (even though I didn't actually run it : I expect it will work).
Now we take a look at the Generated Java for this Activity:
And search for declaration of our local variable; this is what we find:
So, here's my understanding here of why you can't (currently at least) do this in PRPC:
1. Data Transforms don't seem to have any concept of a Local variable - there is nothing on the Params tab, and the syntax Local.variable is not understand.
2. The Local variables defined on Activities are scoped strictly to the Activity itself: they are implemented by defining a Java Field within a Class when the Rule is saved/assembled.
I *guess* what you are after might make a good enhancement: but you would need to 'spec' out exactly how this mechanism would work.
How would the Data Transform know which Local Scoped variables it is able to modify ? (the Design-Time Form would have to contain something that made it aware of calling Activity in order to know what Locals is allowed to modify : or else it would have be totally 'liberal' in what it allows: and then you are trading a design-time syntax-check for a runtime-check (what to do when a non-scoped 'local' isn't available ?)
But then: this is probably the main reason for having a Parameter Page - to avoid having to 'leak' Local Variables from Rule-To-Rule...so it's dubious that an enhancement would bring much additional flexibility here... (but maybe it would ? dunno).
Random follow-up notes:
It is notable that the Local 'a' in the example has a 'public' modifier: so in *theory* outside Java Classes can 'get to it' : but they would still need knowledge of the enclosing scope to know that it exists...
It is also telling that the error you get when trying to save a Data Transform that contains a 'Set' action for a 'Local.<variable>' syntax gives this:
This record has 1 Error in 1 place
Test compilation failed: ----------
1. ERROR in /Rule_Obj_Model_Gcs_scratch_Work_TestDT_Model_20160603T155957_547_GMT.java (at line 60)
a = "hello";
a cannot be resolved to a variable
That is: it appears that the DT does recognize the 'local' prefix, - because the error has managed to parse it out; it essentially knows we are trying to modify a local variable - it's just that the variable happens to not exist; and we have no way of defining any.
Even IF there was a way of setting up a Local Variable on the Params tab of the DT: that wouldn't solve any issues though: you still wouldn't be able to pass in any Local Variables.
The more I think about this: I actually think its a good thing that DTs (or any other called rule) cannot try and modify the Local Scoped variables of the calling variables : this could lead to very difficult to debug issues.....