Run script and local action from a data transform or an activity

About how to run script from a data transform or an activity, I have found some page like

May I know any newer/simpler ways to do so? My current version is Pega 8.6.6.

And how about run local action from an activity?

My purpose is to run script

“pega.ui.HarnessActions.doAttachmentSingleClick”

for downloading file and a local action to show a modal dialog.

They can be called normally from an action set, however caused by when issue as below link, we want to move them to an activity

Local action is running on all conditions | Pega?

Thanks.

@MaxonL16591286

In Pega 8.6.6, you can use the RunScript function to run a JavaScript function from a data transform or an activity.

To run the script “pega.ui.HarnessActions.doAttachmentSingleClick” from an activity, you can use the following syntax:

pega.u.d.doAction(“doAttachmentSingleClick”, parameters);
Where “parameters” is an object that contains any parameters required by the function.

To run a local action from an activity, you can use the following syntax:

tools.getThread().getPage().getActionProcessor().runLocalAction(actionName, actionParams, null);
Where “actionName” is the name of the local action, “actionParams” is an object that contains any parameters required by the action, and null is the context.

Note that in order to run a local action from an activity, the activity must be associated with a section that includes the “pyCaseActionArea” section. This section includes the “RunLocalAction” action set, which is used to run local actions.

Regarding the issue of the local action running all conditions, one solution is to add a when rule to the action set that calls the local action. The when rule should evaluate to true only when the conditions for the local action are met. This way, the local action will only be executed when it is appropriate to do so.

@SumitK989

thanks for your detail solution.

About last part:

"

Regarding the issue of the local action running all conditions, one solution is to add a when rule to the action set that calls the local action. The when rule should evaluate to true only when the conditions for the local action are met. This way, the local action will only be executed when it is appropriate to do so.

"

There will be a problem following above setting, that is, if the when rule do compare on a property that just updated a bit earlier in same action set, it can not retrieve latest value of the property.

E.g. in the action set of a row click event in a table, 1st step is to update a property in the context page, said, A, from space to value “aaa”.

2nd step is to call a local action with when expression or when rule with logic: A=“aaa”, this will not work normally, local action will not run.

@MaxonL16591286

You are correct that if the when rule compares a property that was just updated in the same action set, it may not retrieve the latest value of the property. This is because when rules are evaluated before actions are executed, so the when rule will use the old value of the property.

One possible solution to this problem is to use a different approach for triggering the local action. Instead of using a when rule, you could use an action set variable to store the value of the property after it has been updated, and then use a condition to check the value of the variable before calling the local action.

For example, in your scenario, after updating property A in the context page, you could store its new value “aaa” in an action set variable, let’s say “A_updated”. Then, in the next step of the action set, you could use a condition to check if “A_updated” equals “aaa”, and only if it does, call the local action.

This way, the condition will use the latest value of the property that was updated earlier in the same action set, and the local action will only be executed when it is appropriate to do so.

@SumitK989

I am very interested to your solution!

Could you kindly share more details? May I know what is a “action set variable”? How could I use it in an action set?

I did not find anything related to “action set variable” in an action set config window.

Thanks.

@MaxonL16591286

An “action set variable” is a variable that is defined within an action set and can be used to store data or values that are needed for actions within that set.

To create an action set variable in Pega, you need to first define a property to hold the variable value. You can define this property on any class and make it available to the action set by including the class as a data source. You can then reference this property within the actions of the action set.

To use an action set variable in an action within the action set, you can reference the property using the Property-Set method, for example:

Property-Set .MyVariable = "value"

In the above example, “.MyVariable” is the property that holds the action set variable value, and “value” is the value you want to assign to it.

You can also use action set variables in expressions by referencing the property, for example:

@Equals(.MyVariable, "value")

In the above example, the expression checks whether the value of “.MyVariable” is equal to “value”.

Note that in Pega, the term “action set variable” may not be used explicitly, but the concept of using properties as variables within action sets is widely used. To create and manage properties in Pega, you can use the Data Modeler tool.

@Sumit Kumar

may I know where can I Property-Set method?

As below, no such action. Thanks.

@Sumit Kumar hello, could kindly help for my previous question? thanks.