/**
* Handling redirect to the same portal, where record producer
* has been initially called
*/
var current_url = String(producer.current_url);
if (!current_url){
producer.portal_redirect = "sp?id=submit_successful";
} else {
var portalRedirect = '/' + getPortalFromUrl(current_url) + '?id=submit_successful';
producer.portal_redirect = portalRedirect;
}
/**
* This function gets portal id from the url
**/
function getPortalFromUrl(url){
var regex = /com\/(.+)\?id=/gm;
var m;
var returnResult;
while ((m = regex.exec(url)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach(function(match, groupIndex){
if (groupIndex == 1){
returnResult = match;
}
});
}
return returnResult;
}