- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-15-2022 03:42 AM
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
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-15-2022 09:43 AM
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]);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-15-2022 07:36 AM
i wrote the below onload client script
function onLoad() {
//Type appropriate comment here, and begin script below
//Use the 'getParameterValue' function below to get the parameter values from the URL
var user = getParameterValue('sysparm_company');
g_form.setValue('company', user);
}
function getParameterValue(company) {
var url = document.URL.parseQuery();
if (url[company]) {
return decodeURI(url[company]);
} else {
return;
}
}
o/p
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-15-2022 07:44 AM
Hi,
update onLoad script as this
function onLoad() {
//Type appropriate comment here, and begin script below
//Use the 'getParameterValue' function below to get the parameter values from the URL
var url = top.location.href;
var comp = new URLSearchParams(url).get("sysparm_company");
var user = getParameterValue('sysparm_company');
g_form.setValue('company', comp);
}
OR
function onLoad() {
//Type appropriate comment here, and begin script below
//Use the 'getParameterValue' function below to get the parameter values from the URL
var glideURL = new GlideURL();
glideURL.setFromCurrent();
var comp = glideURL.getParam("sysparm_company");
g_form.setValue('company', comp);
}
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-15-2022 11:01 AM
Hi Ankur,
Thanks a lot for the support and your contribution is highly appreciated sir.
When i try to execute your script I'm getting JavaScript console error in the browser
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-15-2022 08:10 PM
Either of the script should have worked fine
which one you tried?
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-15-2022 07:37 AM
following the brad article :
REF:https://community.servicenow.com/community?id=community_blog&sys_id=ec3eea6ddbd0dbc01dcaf3231f9619d6