Question
Ai4Process
GB
Last activity: 14 Mar 2017 14:07 EDT
How can we launch a URL & pass parameters using HTTP POST instead of as query params in Pega PRPC 6.2 sp2
I need to launch a URL in a new window & pass parameters to it using HTTP POST (instaed of the usual way of passing it in the URL)
This is how it is done in any other web language:
POST /test/demo_form.asp HTTP/1.1
Host: w3schools.com
name1=value1&name2=value2
How can we do this in Pega 6.2?
Message was edited by: Marissa Rogers - Added Category
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Ai4Process
GB
PROBLEM SOLVED!!
We have found a solution for this. Slightly modified the HTML code & it started working now:
document.getElementById('jsonData').value=JSON.stringify(
)
document.forms[0].submit();
</script>
I had to create a form with method as post & provide the URL in that. Then for submitting I used document.forms[0].submit instead of document.main.submit();
Now when I click on the button, I get a window with parameter values :
Summarizing the steps:
1. Create a button or link on your section Rule
PROBLEM SOLVED!!
We have found a solution for this. Slightly modified the HTML code & it started working now:
document.getElementById('jsonData').value=JSON.stringify(
)
document.forms[0].submit();
</script>
I had to create a form with method as post & provide the URL in that. Then for submitting I used document.forms[0].submit instead of document.main.submit();
Now when I click on the button, I get a window with parameter values :
Summarizing the steps:
1. Create a button or link on your section Rule
2. Configure “Open a New URL” option on click & call an activity
3. In the activity, use Show-HTML to display a HTML Stream
4. In the HTML Stream Rule paste the above code & modify the URL & params as per your need (You can use values form clipboard as well)
5. Then test the same by clicking on the button
Thanks Jai for all your help!!
Nikhil
You can use pega.u.d.asyncRequest API in PRPC.
This API accepts 5 parameters,
method - GET / POST
safeURL - safeURL object with the activity to be invoked and params to be passed in the form of query string
callback - success and failure callback object
postData - body of post data containing all the data to be submitted
asyncConfigOptions - async / sync
Ai4Process
GB
Thanks Satish,
This looks like a method to an API to call the URL & get the response in the background.
I have a button from which I need to launch a external URL in a new window (& pass some JSON parameters using POST Method to this external URL)
I have tried the below code but it gives me permission denied in IE. PPl are saying it works in other browsers but haven’t tested it yet.
<html> <head> <Script type='text/javascript'>//<![CDATA[ function openWindowWithPost(url,name,keys,values) { //alert(url); //alert(name); //alert(keys); //alert(values); var newWindow = window.open(url, name); if (!newWindow) return false; var html = ""; html += "<html><head></head><body><form id='form123' method='post' action='" + url +"'>"; if (keys && values && (keys.length == values.length)) for (var i=0; i < keys.length; i++) html += "<input type='hidden' name='" + keys[i] + "' value='" + values[i] + "'/>";
Thanks Satish,
This looks like a method to an API to call the URL & get the response in the background.
I have a button from which I need to launch a external URL in a new window (& pass some JSON parameters using POST Method to this external URL)
I have tried the below code but it gives me permission denied in IE. PPl are saying it works in other browsers but haven’t tested it yet.
<html> <head> <Script type='text/javascript'>//<![CDATA[ function openWindowWithPost(url,name,keys,values) { //alert(url); //alert(name); //alert(keys); //alert(values); var newWindow = window.open(url, name); if (!newWindow) return false; var html = ""; html += "<html><head></head><body><form id='form123' method='post' action='" + url +"'>"; if (keys && values && (keys.length == values.length)) for (var i=0; i < keys.length; i++) html += "<input type='hidden' name='" + keys[i] + "' value='" + values[i] + "'/>";
html = "</form><script type='text/javascript'>document.getElementById('form123').submit();</sc""ript>";
//alert(html);
newWindow.document.write(html);
return newWindow;
}
var values= new Array("value1", "value2", "value3");
var keys= new Array("a","b","c");
//]]>
Nikhil
Virtusa IT Consulting
AE
Hi Nikhil,
You can try below script to pass parameters along with their values, for instance I am passing my page name to the property 'pyPrimaryPageName' and some value to a custom property 'myProperty'.
var prop= SafeURL_createFromURL(pega.u.d.url); // this should return the actual url
prop.put('pyPrimaryPageName','myPage');
prop.put('myProperty','value');
alert(prop.toURL());
Financial Services
AU
Hi Nikhil,
I suggest setting up a html rule (Rule-Obj-HTML) with input types as hidden for all your parameters (example below) and then submit the HTML using JS (example below). You may be able to call this using a link or a button and then setting up an onclick event with action as "Open URL in window" (as below)
<input name="firstname" value="<p:r n='.pyWorkParty(Customer).pyFirstName'/>" type="hidden"/>
<script>
window.onload = function() {
document.main.action='URL';
document.main.method='POST';
document.main.submit();
}
</script>
Please try this and post the results.
Ai4Process
GB
trying to understand your solution:
1. I create a button / link with the standard control pxButton or pxLink in my Section rule form where the user will launch the new window
2. I configure the on click Behavior by using Open URL in new window
3. I configure the URL to be called.
Now where do I call this HTML rule with the javascript for submitting the form that u r talking about? I didn't understand please elaborate
Financial Services
AU
Hi Nikhil,
Call the HTML from an activity (Show-HTML method) which is called through the click behavior.
Ai4Process
GB
Tried it but did not work (I guess coz the activity call & the opening of the URL are not linked to each other)
First I called the activity on click which does a SHOW-HTML & then I called the URL in alternate domain. The URL opened but the parameters were not passed.
I now have got a pure HTML code to work as below:
But when I modify this to use in an HTML rule in Pega it doesn’t work. Any help will be appreciated (due to the highlighted part in the code).
Nikhil
Financial Services
AU
Ai4Process
GB
Tried this but did not work
Am getting a javascript error at the document.main.action=”” step saying Action cannot be set for a null reference.
Accepted Solution
Ai4Process
GB
PROBLEM SOLVED!!
We have found a solution for this. Slightly modified the HTML code & it started working now:
document.getElementById('jsonData').value=JSON.stringify(
)
document.forms[0].submit();
</script>
I had to create a form with method as post & provide the URL in that. Then for submitting I used document.forms[0].submit instead of document.main.submit();
Now when I click on the button, I get a window with parameter values :
Summarizing the steps:
1. Create a button or link on your section Rule
PROBLEM SOLVED!!
We have found a solution for this. Slightly modified the HTML code & it started working now:
document.getElementById('jsonData').value=JSON.stringify(
)
document.forms[0].submit();
</script>
I had to create a form with method as post & provide the URL in that. Then for submitting I used document.forms[0].submit instead of document.main.submit();
Now when I click on the button, I get a window with parameter values :
Summarizing the steps:
1. Create a button or link on your section Rule
2. Configure “Open a New URL” option on click & call an activity
3. In the activity, use Show-HTML to display a HTML Stream
4. In the HTML Stream Rule paste the above code & modify the URL & params as per your need (You can use values form clipboard as well)
5. Then test the same by clicking on the button
Thanks Jai for all your help!!
Nikhil
-
Israel Candelario
CTS
CA
For my requirement I need to launch a external URL along with with parameters like client name, acc no, case id etc.
currently I am using openurlinwindow and using alternative domain url by directly mentioning the URL in the property.
But the URL will be dynamic and I should frame with parameters everytime when I launch my url in window.
can you please paste the HTML code here to use it for framing that url+parameters and opening that in window.
Your help is much appreciated