Discussion

How to call Activity from Javascript?

Hi Friends,
Could you please help me in how to call activity from javascript?
Thanks for help

**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

November 30, 2011 - 2:15am

It helps me.
Thanks a lot

February 15, 2012 - 4:53am

I understand that parameters can be passed to activity from JSP using url.put.
How can i retreive property values (in clipboard) into the JS file ?
How can i collect the output prameter of an activity from JS ?

Thanks,
Gaurav

November 24, 2011 - 11:04am

Try this out

<script>

function openActivity()
{
var oSafeURL = new SafeURL("Ecorp-Report.TestActivity");

openUrlInWindow(oSafeURL, 'popup', 'width=850,height=350,left=100,scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no');
}

</script>

Thanks,
Best Regards,
Austin Jonny

November 25, 2011 - 6:07am

<script language="javascript">
function callActivity(){
openUrlInWindow("pyActivity=PegaSample.PorTalActivity");
}
</script>
<html>
<body>
<a href="javascript:callActivity()"> call new Object</a>
</body>
</html>

Thanks
DP

March 15, 2013 - 3:32am

Hi

i am not able call an acitivity from JSP .

below sample code which i was done in control rule.

Req: i want to display the button control if click on that button then activty should getting called and pop the html rule from that acitivty via show-HTML method.

 

<script>
function openActivity()
{
var oSafeURL = new SafeURL("Link-Attachment.Test");
openUrlInWindow(oSafeURL, 'popup', 'width=850,height=350,left=100,scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no');
}

</script>
 

<table class='buttonMainTable' border='0' cellspacing='0' cellpadding='0' id='<pega:reference name='$this-value' mode="NORMAL"/>'
alt='View Image' title='view Document'>
<tr>
<td class='buttonTdLeft'>&nbsp;</td>
<td class='buttonTdMiddle'><button <pega:include name="ClientValidation"/> ONCLICK=openActivity() class='buttonTdButton'>View Button</button></td>
<td class='buttonTdRight'>&nbsp;</td></tr>
</table>

November 22, 2013 - 4:33pm

<script>
function openActivity()
{
var oSafeURL = new SafeURL("Link-Attachment.Test");
openUrlInWindow(oSafeURL.toURL(), 'popup', 'width=850,height=350,left=100,scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no');
}

</script>

November 23, 2013 - 4:32am

To call an activity using java script : 

1) 

    var bSafeURL= new SafeURL("A-B-C.ActivityName");
    bSafeURL.put("param1",value1);
    bSafeURL.put("param1",value2);

    pega.util.Connect.asyncRequest('GET', bSafeURL.toURL(),'');

 

2) var oSafeURL = new SafeURL("@baseclass.testActivity");

oSafeURL.put("ClassName", insName);
var strRuleXml = httpRequestAsynch( oSafeURL.toURL(), null, 50, 100);

 

apart from there there lot other ways to do it. 

 

Some ways that we can achive a  call to activity and open popup window / model window

 

1) openUrlInWindow(pxReqURI + "?pyActivity=A-B-C.ActivityName&Param1=" + value1, "InteractionData", "status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,left=192,top=51.2,height=500,width=800");

pxReqURI = pxRequestor.pxReqURI value

 

2)

activityURL = "<pega:reference name="pxRequestor.pxReqURI" mode="normal"/>?pyActivity=Work-myActivity&myParameterName=" + valueToPass;
windowOptions = "width:500;height:600;resizable: yes; scroll: yes; help: no";
openUrlInWindow(activityURL,"WINDOWNAME",windowOptions,false);

 

3) 

 var strWindowName = "Popup window title";
 
 var objSafeUrl = new SafeURL("A-B-C.Activity Name");
 var contentWin = showModalDialog(objSafeUrl.toURL(), strWindowName , "width:500;height:600;resizable: yes; scroll: yes; help: no;");

 

4)   var objSafeUrl = new SafeURL("A-B-C.Activity Name");

windowOptions = "width:500;height:600;resizable: yes; scroll: yes; help: no";
openUrlInWindow(objSafeUrl .toURL(),"WINDOWNAME",windowOptions,false);

 

 

May 11, 2014 - 11:52pm

Hello,

I am using below code to call the activity from javascript. And I want to receive multiple parameters back inside control. I am using show-property inside activity to take one parameter back to control. Is there anything like bSafeURL.put("param3",value3); to recive output parameter in activity back to control?

var bSafeURL= new SafeURL("A-B-C.ActivityName");
bSafeURL.put("param1",value1);
bSafeURL.put("param1",value2);

 

Regards

Mandar

 

May 12, 2014 - 1:06am

you can return mulitple values in show-property Method. you can try like

Param.ReturnValues="Value1 :"+.value1+","+"Value2 :"+.value2

or

Param.ReturnValues=.value1+","+.value2

 

AND use this Param in the show-property . In java script , you can parse CSV.

May 12, 2014 - 2:19am

Superb!!!!!!!!!!!!!!!!!

 

Thanks a lot.. Its working. :)

December 4, 2014 - 8:53am

Hi,

 

I am trying to open the work object and render the flow action on click of the url. But I am getting a blank screen. It is because the WO is opening in a different thread which is not popping up on the screen.

Hence, I am calling the below script in the section(Which is embedded in the harness; which is further refered in the portal).

 

<script type=text/javascript>

window.attachEvent("onload", fnName);

function fnName()
{
alert("hi1");

oSafeURL =null;
var oSafeUrl = new SafeURL("ClassName.TestActivity",getReqURI());
oSafeUrl.put("param1","value1");
oSafeUrl.put("param2","value2");
pega.util.Connect.asyncRequest('GET',oSafeURL.toURL());
alert("hi2");
}

</script>

The logic in the 'TestActivity' is to do an to do an Obj-Open  by handle and call the activity 'StartNewFlow'.I am still not able to render the flow action.

Can you please advice.

 

Note: It is poping up hi1 and hi2.

December 9, 2014 - 12:38pm

you can try passing teh pzPrimaryPageName paramater to the safe URL. activity do not need any additional paramter. just add this paramter with the primary page name map to it.

var oSafeUrl = new SafeURL("ClassName.TestActivity",getReqURI());
oSafeUrl.put("param1","value1");
oSafeUrl.put("param2","value2");

oSafeUrl.put("pzPrimaryPageName","pyWorkPage");
pega.util.Connect.asyncRequest('GET',oSafeURL.toURL());

 

when you setting the primary page value try to get it dynamically using the api methods. for ex:(tools. getPrimaryPage().getName()) or according to the context you are in the methods will vary.

tools.getActive().getPageValue().getName() if this is used in a control which use the StreamBuilderToolKit.

or if called using activity step tools.getStepPage().getName() would do.

Just give it a try this may solve the issue.

Note: i really do not exactly remember the methods name and if those are corret but this will give you some idea to find out. :)