Question

How to run an activity through JavaScript.
How to run an activity through JavaScript. I dont want to use OpenURLInSpace,
I just want to run the activity from the back end and nothing should be visible in the UI.
-
Likes (2)
-
Accepted Solution

Please find the sample code below and let us know if this helps.
var oSafeUrl = new SafeURL("@baseclass.ActivityName");
var request = pega.u.d.asyncRequest('GET',oSafeUrl);

Just adding to whatever Pankaj Rawal replied.
Added Success/Failure functions as well. Incase due to some reason if the asyncRequest call to the Activity fails we can handle it in a better way.
<script>
function FunctionName(e) {
var oSafeURL = new SafeURL("ClassName.ActivityName");
oSafeURL.put("pzPrimaryPageName", "pyWorkPage");
pega.util.Connect.asyncRequest("POST", oSafeURL.toURL(), {
success: function (o) {
<<Do Something>>
},
failure: function (o) {
<<Do Something>>
}
}, '');
}
</script>
Thanks
Hari Kumar Alampuru

Hi Hari,
We are using below control for adding notes in case notes tab by click on submit button in pop up window which will trigger activity for attaching notes.
<script>
function SaveAndClose()
{
var successMessage = "";
var failureMessage = "";
var oSafeBaseUrl = new SafeURL("ActivityClassName.ActivityName");
var request = pega.util.Connect.asyncRequest('POST', oSafeBaseUrl.toURL());
/*window.opener = self; */
window.close();
}
</script>
<input type = 'Button' value = 'Submit' onclick = "SaveAndClose()" />
But activity is not triggering in Prod environment only for some reason. Will it be environmental issue or any configuration needs to be done for triggering activity.

Thanks for the reply Pankaj and Hari âº, Will try the above mentioned method and share the result.

Thanks Pankaj Rawal and Hari Kumar, Both the method worked âºâº

Also is it possible to return values from the calling url ?

Yes, in the above post by Hari, he mentioned about callback functions like success as
success: function (o)
here o refers respObject which can be further used as appropriate.
say var retHTML = respObject.responseText;

okay thanks for the response,i have one more doubt, to set the response we use something like pxRequestor.pyHTTPResponse Header in the activity that was called through url?