web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Dynamics 365 Portals (CRM Portals) Redirect Not Working (Javascript)

(0) ShareShare
ReportReport
Posted on by 480

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):-

Portals-Pay.png

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

I have the same question (0)
  • Mahendar Pal Profile Picture
    45,095 on at

    Hi Rizwan,

    Real time workflow will first complete processing after that it will process other things. But once it is completed it should execute your rest of the code.

  • Rizwan Aarif Profile Picture
    480 on at

    Hi Mahendra,

    I want my redirect script (js) to be executed once realtime workflow is completed. What is the best way to do so? We can add few seconds wait also, that will be fine. but it needs to redirect users to payment page as I mentioned.

  • sandeepstw Profile Picture
    4,601 on at

    hi,

    Instead of creating a page, I will suggest to create a web template which return invoice id. Which you can call using Ajax and it will be faster then current process. Your code looks good. I think it will take time to complete process and redirect to next page.

    also use window.location = "URL";

    Please visit this page for web template return json data.

    colinvermander.com/.../dynamics-365-portals-use-liquid-to-return-json-or-xml

  • Rizwan Aarif Profile Picture
    480 on at

    Hi Sandeep,

    Thanks for your suggestion. I agree It would be faster but will that resolve the issue with redirection ?

  • Suggested answer
    Arpit Shrivastava Profile Picture
    7,518 User Group Leader on at

    Hi Rizwan,

    Once you click on the button (OOB action button) in order to call your real-time workflow. OOB It gives you a success message, isn't it?  Like: Workflow has been successfully initiated, Record has been deactivated etc. 

    I also had the similar requirement. What you can do is, on click of the button show the loader image/ In progress message and let your script do the magic behind. Using script wait to get the success message. As soon as it appears, retrieve the Guid of created record either using Odata or fetch xml and then redirected to the payment page.

    Hope you understood.

    -Arpit

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans