- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2017 05:48 AM
Hello,
I have a requirement to redirect to a Service Catalog item from a UI Action Form Button and set a specific value that will trigger other fields to be populated. I currently have the UI Action in place and it is redirecting to the correct Catalog Item, however I'm having trouble setting the value on the Catalog Item. Below is the code for my UI Action and Script Include:
UI Action:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2018 12:05 PM
I ended up passing the form values to the catalog form through the URL. Code is below:
Catalog Client Script:
function onLoad() {
//Type appropriate comment here, and begin script below
var user = getParmVal('sysparm_user');
var first_name = getParmVal('sysparm_first_name');
var last_name = getParmVal('sysparm_last_name');
var user_id = getParmVal('sysparm_user_id');
var email = getParmVal('sysparm_email');
var business_phone = getParmVal('sysparm_business_phone');
var mobile_phone = getParmVal('sysparm_mobile_phone');
var street = getParmVal('sysparm_street');
var street2 = getParmVal('sysparm_street2');
var city = getParmVal('sysparm_city');
var state = getParmVal('sysparm_state');
var zip = getParmVal('sysparm_zip');
if(user){
g_form.setValue('user_ref', user);
g_form.setValue('first_name', first_name);
g_form.setValue('last_name', last_name);
g_form.setValue('user_id', user_id);
g_form.setValue('email', email);
g_form.setValue('business_phone', business_phone);
g_form.setValue('mobile_phone', mobile_phone);
g_form.setValue('street', street);
g_form.setValue('street2', street2);
g_form.setValue('city', city);
g_form.setValue('state', state);
g_form.setValue('zip', zip);
}
function getParmVal(name){
var url = document.URL.parseQuery();
if(url[name]){
return decodeURI(url[name]);
} else {
return;
}
}
}
UI Action form button:
var user = current.sys_id;
var first_name = current.first_name;
var last_name = current.last_name;
var user_id = current.user_name;
var email = current.email;
var business_phone = current.phone;
var mobile_phone = current.mobile_phone;
var street = current.street;
var street2 = current.u_street2;
var city = current.city;
var state = current.state;
var zip = current.zip;
gs.setRedirect('com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=1248c78d37440f40f51ea6d2b3990e67&sysparm_user=' + user + '&sysparm_first_name=' + first_name + '&sysparm_last_name=' + last_name + '&sysparm_user_id=' + user_id + '&sysparm_email=' + email + '&sysparm_business_phone=' + business_phone + '&sysparm_mobile_phone=' + mobile_phone + '&sysparm_street=' + street + '&sysparm_street2=' + street2 + '&sysparm_city=' + city + '&sysparm_state=' + state + '&sysparm_zip=' + zip);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2017 12:47 PM
Yeah, so... UI action?
Anyway, variables in the item should be referred to as x.variables.VARIABLE_NAME
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2017 02:09 PM
Hi Michael,
You can use user session to get the fields value and populate it you catalog varible.
say forr example if you have two field value1 and value2 amd you want to populate these value on a particular catalog item.
You can add below code in your ui action
gs.getSession().putClientData('test1', 'value1'); gs.getSession().putClientData('test2', 'value2');
To take these value in your catalog item you have to write a catalog client script.
You can use the below method to get those value
varv = g_user.getClientData('test1');
Finally you have to setValue method to set the value of your variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2017 03:01 AM
Hello,
I worked on similar requirement, please find below script:
UI Action:
var session = gs.getSession();
session.putClientData('requested_for', current.caller_id.name);
session.putClientData('short_description', current.short_description);
session.putClientData('description', current.description);
url="nav_to.do?uri=/catalog_home.do%3Fsysparm_view%3Dcatalog_default";
action.setRedirectURL(url);
Create a onload catalog client script with below script:
function onLoad() {
//Type appropriate comment here, and begin script below
var sd = g_user.getClientData('short_description');
g_form.setValue('short_description', sd);
var desc = g_user.getClientData('description');
g_form.setValue('description', desc);
var req = g_user.getClientData('requested_for');
g_form.setValue('requested_for', req);
}
**Please Hit like, Helpful or Correct depending on the impact of the response
Thanks,
Nikhil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2018 07:26 AM
Yes its working great.