Requirement: How to pass Variables to catalog item in service portal via URL and share the URL to end Users when user clicks on the URL it should land them in a catalog item with prepopulated fields can any one help me with this requirement please.

krishh2
Tera Expert

I was designing the virtual agent topic with some components once the user provides the inputs we need to present the catalog item with prepopulated fields 

1 ACCEPTED SOLUTION

krishh2
Tera Expert

Hi All,

Thanks a lot for the support 

This below code is working :

function onLoad() {

      //Use the 'getParameterValue' function below to get the parameter values from the URL  

      var user = getParameterValue('sysparm_user'); 

      if (user) {

              g_form.setValue('user_variable', user);

      }

}

 

function getParameterValue(name) {

      name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");

      var regexS = "[\\?&]" + name + "=([^&#]*)";

      var regex = new RegExp(regexS);

      var results = regex.exec(top.location);

      if (results == null) {

              return "";

      } else {

              return unescape(results[1]);

      }

}

***********************to fetch multiple values***************************

function onLoad() {

//Use the 'getParameterValue' function below to get the parameter values from the URL

var user = getParameterValue('sysparm_company');
var user1 = getParameterValue('sysparm_email');


if (user) {

g_form.setValue('company', user);

}
if (user1) {

g_form.setValue('email', user1);

}

}

function getParameterValue(name) {

name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");

var regexS = "[\\?&]" + name + "=([^&#]*)";

var regex = new RegExp(regexS);

var results = regex.exec(top.location);

if (results == null) {

return "";

} else {

return unescape(results[1]);

}

}

View solution in original post

10 REPLIES 10

krishh2
Tera Expert

Hi All,

Thanks a lot for the support 

This below code is working :

function onLoad() {

      //Use the 'getParameterValue' function below to get the parameter values from the URL  

      var user = getParameterValue('sysparm_user'); 

      if (user) {

              g_form.setValue('user_variable', user);

      }

}

 

function getParameterValue(name) {

      name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");

      var regexS = "[\\?&]" + name + "=([^&#]*)";

      var regex = new RegExp(regexS);

      var results = regex.exec(top.location);

      if (results == null) {

              return "";

      } else {

              return unescape(results[1]);

      }

}

***********************to fetch multiple values***************************

function onLoad() {

//Use the 'getParameterValue' function below to get the parameter values from the URL

var user = getParameterValue('sysparm_company');
var user1 = getParameterValue('sysparm_email');


if (user) {

g_form.setValue('company', user);

}
if (user1) {

g_form.setValue('email', user1);

}

}

function getParameterValue(name) {

name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");

var regexS = "[\\?&]" + name + "=([^&#]*)";

var regex = new RegExp(regexS);

var results = regex.exec(top.location);

if (results == null) {

return "";

} else {

return unescape(results[1]);

}

}