Passing Parameters through the URL

theiser
Tera Expert

I have successfully been able to create a UI Action that creates a URL with specific parameters that I pass to a catalog item and then will be rerouted to the item. The catalog item opens with no issues and is then populated with the specific parameters. I am using a   catalog client script — onLoad in order to read and parse the URL and to set fields in the form.

 

My issue. This only works in the backend of the system. The front end, where a user would be redirected, does not populate the form. Any clues as to why.

12 REPLIES 12

Slava Savitsky
Giga Sage

Could you please share the code of the client script you are using as well as a sample URL generated by your UI action?


Here is the code.



UI Action


gs.addInfoMessage('You will need to navigate back to your Project Information upon request completion');


var url = "com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=84c65f1daca36100e1ab6d54a23c92cc"


url += '&sysparm_project_name=' + current.u_project_name;


url += '&sysparm_tenant=' + current.u_acronym;


url += '&sysparm_operations_area=' + current.u_operations_area;


url += '&sysparm_admin_group=' + current.u_ad_group_name;


url += '&sysparm_first_name=' + first_name;


url += '&sysparm_last_name=' + last_name;


url += '&sysparm_email=' + email;


action.setRedirectURL(url);



Catalog Client Script


function onLoad() {


  //Populate the variables with the parameters passed in the URL


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



  var tenant = getParmVal('sysparm_tenant');


  var project_name = getParmVal('sysparm_project_name');


  var operations_area = getParmVal('sysparm_operations_area');


  var admin_group = getParmVal('sysparm_admin_group');


  var first_name1 = getParmVal('sysparm_first_name');


  var last_name1 = getParmVal('sysparm_last_name');


  var email1 = getParmVal('sysparm_email');



  g_form.setReadonly('project_name',true);


  g_form.setReadonly('tenant',true);


  g_form.setReadonly('operations_area',true);


  g_form.setReadonly('admin_group',true);


  g_form.setReadonly('first_name1',true);


  g_form.setReadonly('last_name1',true);


  g_form.setReadonly('email1',true);


  fix_readonly_field_colors();


  if(project_name){


  g_form.setValue('project_name',project_name);


  }


  if(tenant){


  g_form.setValue('tenant',tenant);


  }


  if(operations_area){


  g_form.setValue('operations_area',operations_area);


  }


  if(admin_group){


  g_form.setValue('admin_group',admin_group);


  }


  if(first_name1){


  g_form.setValue('first_name1',first_name1);


  }


  if(last_name1){


  g_form.setValue('last_name1',last_name1);


  }


  if(email1){


  g_form.setValue('email1',email1);


  }


}



function getParmVal(name) {


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


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


  var regex = new RegExp(regexS);


  var results = regex.exec( window.location.href );


  if(results == null){


  return "";


  }


  else{


  return unescape(results[1]);


  }


}


Can you do a alert( window.location.href); for checking if the URL is correct or not?


theiser
Tera Expert

Now that I have done some error-checking, the parameters are being passed correctly, they just aren't not being set using the g_form.setValue.