Redirect to External URL in Business rule

chrisn_
Mega Guru

I am attempting to redirect to an external url after a user submits a record and a particular field is filled with a unique value. I need to take that unique value, plug it on the end of a static url and then redirect to it. example is 

https://iwantmystuff/service/{unique value}. I believe what I need to do is define the url using something like

var url = gs.generateURL  and then gs.setRedirect(url); but I am not utilizing this correctly as I am commenting out most of the code due to the // in the first line. I am obviously making a rookie error I don't realize. Can someone please help me craft this correct? The unique value is coming from a scoped application that is open to global scripts so this should be accessible. Do I also need to do a separate call for that unique value's value? To those who stop by, thank you very much for your time!

1 ACCEPTED SOLUTION

DScroggins
Kilo Sage

Hello please try the following:

var mainURL = 'https://iwantmystuff/service/';

var urlFinal = mainURL + current.FIELD_NAME.toString(); //Replace with your form field

gs.setRedirect(urlFinal);

 

--David

View solution in original post

12 REPLIES 12

Hello unfortunately you cannot do what you would like due to the nature of the before query business rule. The BR runs against the User table and has no visibility into from where it is being triggered. It simply intercepts the database query against the User table and adds the active parameter.

Hi David,

Thank you for the response.

Can we restrict only that catalog form by using URL and variable sysid..

Thank you,

Priya.

I suppose you can try using gs.getUrlOnStack() to check the current URL and then check if the sys id of the catalog item is present or not. If it is then you can exclude the addActiveQuery condition. Something like so:

var curURL = gs.getUrlOnStack();
var itemID = SYS_ID // Replace with Sys ID of your catalog item
var n = curURL.search(itemID);

  if(n < 0){
     current.addActiveQuery();
  }

Hi David,

Thanks for your suggestion.

Can we add variable sys_id as well to the script to be more specific.

 

Thank you,

Priya.

No you cannot. You can only identify what is in the URL and variable sys id isn't included in the URL.