- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2019 01:47 PM
Within a scoped app, I have a UI action on a custom table form with the following code:
var nameCI = current.name;
var comp = current.invoice_parent.company;
var url = 'cmdb_ci.do?sys_id=-1&sysparm_view=contract_management&sysparm_view_forced=true?sysparm_CIname=' + nameCI + '?sysparm_Comp=' + comp;
action.setRedirectURL(url);
action.setReturnURL(current);
This works. Then I have an onLoad client script where I want to take the parameter values being sent in the url to populate fields. I've seen similar code working so I don't know if it's because I'm in a scoped app but it's not working. It doesn't populate. Even the addinfoMessage or setMandatory pieces don't work. I had an addInfoMessage at the start and that did work so I know the script is triggering. Any idea why I can't use the getParameterValue function here? Or does someone have another way to send values from a UI action to a client script in a scoped app? I've tried setting isolate script to true and this also does not have any effect. Thanks!
function onLoad() {
g_form.setMandatory('model_id', true);
var nm = getParameterValue('sysparm_CIname');
if (nm) {
g_form.setValue('name', nm);
} else {
g_form.addInfoMessage('no name');
}
var comp = getParameterValue('sysparm_Comp');
if (comp) {
g_form.setValue('company', comp);
}
}
function getParameterValue(name) {
var url = document.URL.parseQuery();
if (url[name]) {
return decodeURI(url[name]);
} else {
return;
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2019 06:03 PM
Can you try commenting out this line in your UI action
//action.setReturnURL(current);
See if the url alert goes to cmdb_ci
Also can you check the url formation. it has some extra '?'
It should be
var url = 'cmdb_ci.do?sys_id=-1&sysparm_view=contract_management&sysparm_view_forced=true&sysparm_CIname=' + nameCI + '&sysparm_Comp=' + comp;
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2019 05:56 PM
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2019 06:17 AM
/*Tested on PDI. Thanks to Ankur*/
function getParameterValue(name) {
var glide_url = new GlideURL();
glide_url.setFromCurrent();
var target = glide_url.getParam(name);
if (target) {
return decodeURI(target);
} else {
return;
}
}
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2019 08:04 PM
Hi,
if on your client script showing info message in blue color then you have to set 'glide.script.block.client.globals' into sys_properties.LIST and set value to false
and write
function getParmVal(sys_id)
{
var url = document.URL.parseQuery();
if(url[sys_id])
{
//return decodeURI(url[sys_id]);
alert(decodeURI(url[sys_id]));
}
else
{
return;
}
}
This works for me. Hope it will works for you as well
Thanks
Sayali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2019 07:03 AM
sn_si.glide.script.block.client.globals was set to false. Unfortunately this didn't work for me with this code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2019 08:29 PM
Hi Sheryl,
document object won't work in scoped app
Can you update code as below and check once. this should work; try either of the approach
function onLoad() {
g_form.setMandatory('model_id', true);
var nm = getParameterValue('sysparm_CIname');
if (nm) {
g_form.setValue('name', nm);
} else {
g_form.addInfoMessage('no name');
}
var glideURL = new GlideURL();
glideURL.setFromCurrent();
var comp = glideURL.getParam("sysparm_Comp");
if (comp) {
g_form.setValue('company', comp);
}
}
OR
function onLoad() {
g_form.setMandatory('model_id', true);
var nm = getParameterValue('sysparm_CIname');
if (nm) {
g_form.setValue('name', nm);
} else {
g_form.addInfoMessage('no name');
}
var url = top.location.href;
var comp = new URLSearchParams(url).get("sysparm_Comp");
if (comp) {
g_form.setValue('company', comp);
}
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader