Discussion

How to call Activity from Java Script

Hi
I am looking for How to call Activity from Java Script
can someone point me to API

**Moderation Team has archived 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

July 10, 2011 - 1:20am

Hi
I am looking for How to call Activity from Java Script
can someone point me to API
Also an example how to pass paramenters

July 11, 2011 - 3:09am

try the below code. It may be helpful.
handleClientEvent("SERVER","activity","Parmeters","-1",event);

July 11, 2011 - 3:29am

Hi,

There are two ways to call an activity from Java Script. One is for HttpAsynch and another one is Ajax call.

Calling Activity using HttpAsynch:

var xmlUrl = new SafeURL("@baseclass.testActivity");
xmlUrl.put("ClassName", insName);
var strRuleXml = httpRequestAsynch( xmlUrl.toURL(), null, 50, 100);

if we want to pass xml then we can pass xml as second parameter to httpRequestAsynch.

Like var strRuleXml = httpRequestAsynch( xmlUrl.toURL(), PRXML, 50, 100);

Call Activity using Connect :

var xmlUrl = new SafeURL("@baseclass.testActivity");
xmlUrl.put("ClassName", insName);

var callback = {
success : function(oResponse){
var xmlData = oResponse.responseText;
/* need to add code whatever you need to do after executing activity. */
},
failure : function(oResponse){
}
};

pega.util.Connect.asyncRequest('GET', xmlUrl.toURL(),callback); or
pega.util.Connect.asyncRequest(‘POST’, xmlUrl.toURL(),callback);

July 11, 2011 - 7:28am

I am using

var xmlUrl = new SafeURL("ClassName.activity");
xmlUrl.put("param1", var1);
var strRuleXml = httpRequestAsynch( xmlUrl.toURL(), null, 50, 100);

but getting error object expected, not sure why

July 11, 2011 - 7:56am

I am not sure about this. But I'll tell you one work around.
Please include httprequestscrip.js text file in the script file and call this function.

httpRequestAsynch function was not able find in that case. So, if you include httprequestscrip.js file it will resolve.

You can try with Ajax call also.Ajax call was a good approach for future also.

July 11, 2011 - 8:20am

ok .. will try same
way of passing param is correct ?

July 11, 2011 - 8:29am

Yes.

August 22, 2011 - 3:03am

Hi,

Was the second method(AJAX call) a SYNCHRONOUS call?

August 22, 2011 - 2:32pm

Hi ABIRMONDAL,
your code has a variable which is not defined and thats why you got object expected error.
xmlUrl.put("param1", var1); // you should have already defined the var1

Pega
August 22, 2011 - 2:46pm

What is the actual usecase that you are looking to build into the screen with the Activity that you call from js?

June 9, 2014 - 1:46pm

Hi ,

I have used the following code to call an activity

var bSafeURL= new SafeURL("ZNA-Data-ClmCmp-PtyInvInClm.shuffleclaimants");
    pega.util.Connect.asyncRequest('GET', bSafeURL.toURL(),'');

But the steppage is showing as null.Can you help me in this??