- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2017 09:02 AM
Here is my problem:
I have created a custom table within a scoped app, and I have added a UI action to show a link on the form for this table in order to launch a specific record producer. In the UI action I have the following script:
var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=683d4adf0f4c43006a4a419ce1050e91';
gs.getSession().putClientData('room',current.sys_id);
action.setRedirectURL(url);
This UI Action fails to execute (drops me back to the list view without redirecting.)
If I create this exact same UI Action in global against a global table, it executes fine and the session variable 'room' is available for me to 'getClientData()' from the record producer.
From this I have guessed that I cannot putClientData() from within a scoped app.
First of all, WTH. Secondly, is there an alternative that would allow me to pass a value from a UI action to a record producer so I can do something nice and simple like populate a record producer field?
Thanks for the help!
Brian
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2017 02:42 PM
Hi Brian, Did you solve your issue? In a case that someone would need a solution; I've just finished an implementation for scoped application using sessions;
My goal was to pass current sys_id to "scripted filter" used in report
My solution:
1) UI Action :
var session = gs.getSession();
session.putClientData('sysID', current.sys_id.toString()); //!!!! IMPORTANT need to pass string
var published_url = '/sys_report_display.do?sysparm_report_id=8c4e773adb300300e1dc72ffbf961949';
action.setRedirectURL(published_url);
my script include:
client callable: true
name: getCurrentEvent
Script:
function getCurrentEvent(){
var session = gs.getSession();
var event = session.getClientData('sysID');
//session.clearClientData('sysID');
return event;
}
or to get session values in client side:
create client script onLoad and call var v = g_user.getClientData('sysID');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2017 09:26 AM
have you tried adding a sysparm in the URL with the value and pulling it out in a client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2017 09:42 AM
Yes I have. I followed the guidance of Mark Stranger here https://www.servicenowguru.com/scripting/client-scripts-scripting/parse-url-parameters-client-script...
This failed as well.
It was a bit confusing to troubleshoot, too, since the displayed URL in the browser's address bar is just the base instance URL, and anything I've tried in the catalog client script to parse the URL into alerts or the log made me think that the record producer does not show sysparm values at all. Which doesn't necessarily make sense, but rather than drill into that further I thought I would try the session variable.
-- Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2017 02:42 PM
Hi Brian, Did you solve your issue? In a case that someone would need a solution; I've just finished an implementation for scoped application using sessions;
My goal was to pass current sys_id to "scripted filter" used in report
My solution:
1) UI Action :
var session = gs.getSession();
session.putClientData('sysID', current.sys_id.toString()); //!!!! IMPORTANT need to pass string
var published_url = '/sys_report_display.do?sysparm_report_id=8c4e773adb300300e1dc72ffbf961949';
action.setRedirectURL(published_url);
my script include:
client callable: true
name: getCurrentEvent
Script:
function getCurrentEvent(){
var session = gs.getSession();
var event = session.getClientData('sysID');
//session.clearClientData('sysID');
return event;
}
or to get session values in client side:
create client script onLoad and call var v = g_user.getClientData('sysID');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2017 08:12 AM
So I finally got around to double checking my code on this, and I want to post my results:
The problem, as a reminder, was to create a UI action that launches a record producer and populates the CI field on the producer with a field from the original form. This was made slightly more problematic by the fact that this is a custom application developed in scope.
The UI Action
var session = gs.getSession();
session.putClientData('cmdb_ci', current.room.toString());
var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=<record producer sys_id>';
action.setRedirectURL(url);
The Catalog Client Script (attached to the record producer)
function onLoad() {
var thisRoom = g_user.getClientData('cmdb_ci');
g_form.setValue('cmdb_ci', thisRoom);
}
Works like a charm. Thanks for the help, community.