1

Instead of using a Link in guidewire I want to use a button to kick off a URL using POST.. example:

<form name="input" method="Post" id="aerForm" name="aerForm" action="https://geico.com">
    <input type="hidden" name="rs:command" id="rs:command" value="test"/>
    <input type="hidden" name="rs:Format" id="rs:Format" value="PDF"/>
    <input type="hidden" name="rc:Toolbar" id="rc:Toolbar" value="false"/>
    <input type="submit" value="Get your total">
</form>

I am not sure how to use this in studio or if there is a different way to achieve this. Does anyone have experience with this?

iceMan33
  • 359
  • 2
  • 16

1 Answers1

2

You can use javascript to do that.

  1. En customer.js file you need to add a function like this.

function createFormAndSubmit(formTxt)
{
 formTxt = formTxt.split("&lt;").join("<");
 formTxt = formTxt.split("&gt;").join(">");
 formTxt = formTxt.split("'post'>").join("'post' >");
 var parser = new DOMParser();
 var formElement = parser.parseFromString(formTxt,"text/xml").documentElement;

 var newForm = document.createElement('FORM');
 newForm.name = 'NewForm';
 newForm.method = 'POST';
 newForm.action = formElement.getAttribute("action");
 newForm.target = 'NewFormTab';
 newForm.style.display = "none";

 for(var i = 0; i < formElement.childNodes.length; i++) {
  var node = formElement.childNodes[i];
  var name = node.getAttribute("name");
  var value = node.getAttribute("value");
  if (name == "null") {
   continue;
  }
  var inputbox = document.createElement('INPUT');
  inputbox.type = 'HIDDEN';
  inputbox.name = name;
  inputbox.value = value;
  newForm.appendChild(inputbox);
 }
 document.body.appendChild(newForm);
 newForm.submit();
}
  1. In PCF file you need to add a TemplatePanel like this.

<TemplatePanel><![CDATA[<script>function callMyForm() {createFormAndSubmit("${new organization.package.MyClass().getFormString(policyPeriod)}")}</script>]]></TemplatePanel>
  1. In the Button action call the created function

<ButtonInput action="javascript:callMyForm()" id="MyFormButton" value="displaykey.MyFormButtonLabel"/>
Carlos Duque
  • 482
  • 3
  • 7
  • I still get createFormAndSubmit is not defined error. – iceMan33 Apr 12 '19 at 17:40
  • Hi. Gosu function "organization.package.MyClass().getFormString(policyPeriod)" must return the form as String. About "not define error" try to restart the IDE, GW have two customer.js files, the function must be in both. – Carlos Duque Apr 12 '19 at 18:00
  • I dont understand the template panel piece. Why would i pass policyPeriod. I don't have policyPeriod on the page i am on. – iceMan33 Apr 12 '19 at 18:24
  • Only is an example. In my case I need to create the form dynamicly but if you don't need that you can have the String hardcoded. – Carlos Duque Apr 12 '19 at 18:34
  • So I would call the javascript function in the TemplatePanel like this: function callMyForm() {createFormAndSubmit()} - I need to pass url to that function? – iceMan33 Apr 12 '19 at 18:40
  • You need pass a String to that function, by ex. callMyForm() {createFormAndSubmit('
    ')}
    – Carlos Duque Apr 12 '19 at 18:55
  • anything needed in the all.js file? I keep getting an error saying: Uncaught ReferenceError: createFormAndSubmit is not defined at callMyForm (eval at (all.js?ver=8.0.4.393:18), :1:24) at eval (eval at me.handler (all.js?ver=8.0.4.393:421), :1:1) – iceMan33 Apr 12 '19 at 19:13
  • I've added my function to both customer.js files but still issue is saying its not defined. – iceMan33 Apr 12 '19 at 19:13
  • No, the function only must be in customer.js. Try with incognito window because JS files are cached in browser, may be the browser are trying to evaluate with old customer.js – Carlos Duque Apr 12 '19 at 19:33