Hi Everyone,
I have a button on a web form step and on click of it I have configured to run a realtime workflow in CRM (Portals OOB feature). This workflow generates an Invoice in CRM. My requirement was to get the GUID of Invoice which is created by this workflow but I did not find a direct way to do it. After getting the GUID I need to redirect the user to a payment page (I have Integrated a Payment Gateway) say https://myportal.com/PayNow/?invoiceid={{INVOICE_GUID}}.
I am able to get the GUID of Invoice created as required using a tricky way (i.e. created a dummy page with fetchquery returning the GUID) but Redirect functionality is not working in one-go. I have to click the button 2-3 times then it works. For redirect, I have added javascript and bind a .onclick event (client side) to the same workflow button (start payment process):-
Below is My Web Form Step (Portals):-
Below is the script I have added in custom script javascript section in Portals:-
debugger; //bind function with click event of WORKFLOW button $('.workflow-link').click(function() { document.getElementById("paymentmsg").style.display="block"; redirecttopay(); }); //function to query data from CRM and get the Guid + REDIRECT function redirecttopay() { var evid=getQueryStringValue("id"); //this page has snippet having fetchxml to retrieve INVOICE GUID var pageurl = "/events/event/event-query/?eventid=" +evid; $.ajax({ async: false, url: pageurl, type: "get", success: function(response) { var n = response.indexOf("invoiceid"); var invoiceGuid = response.substring(n+12, n+48); window.location.href="/pay-invoice/?id=" + invoiceGuid; return false; }, error: function(xhr) { } }); } //function to get id of event from URL function getQueryStringValue (key) { return decodeURIComponent(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + encodeURIComponent(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1")); }
Can someone suggest why it's not working? Is the default behaviour of workflow button (as it blocks UI) preventing the redirect from happening?
Many Thanks in Advance.
*This post is locked for comments