- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2014 03:06 PM
I'm part of a team developing a Custom ServiceNow Application - the "Appointments" application. What we're doing with that application is: on the Incident form, show a "Schedule Appointment" button, and that button then redirects to a Calendar Report of our custom Appointments table of "Available" timeslots. When you click on a link in the report In that table, it brings up the Update Appointment form. The Update Appointment form has a Reference Field to Incident. To avoid bad/wrong input data on that field, I want to pre-fill that field with the sys_id of the Incident that the user was looking at when the user clicked the button.
My problem: how to feed that sys_id value into the Appointment form.
Things I have already explored:
1. query string. Passing a query string value from Incident to the Calendar Report works, but once there: I can't get it into the form link and -- in any case -- clicking on any of the report buttons erases the query string.
2. g_scratchpad. I thought this might work the same way as a session variable, but not so much. It's more of a "viewstate" variable, and is limited to a single form/table. You can't load g_scratchpad on one form, and then consume it on another.
3. global application variable. I think this might work, but would be undesirable as everyone would have the same value (and be writing/rewriting the value) so it's not a per-user or per-session variable and making it global means it needs to execute on every transaction.
I'm tentatively leaning towards:
4. Creating a custom Session State table to hold additional values (like incident.sys_id in a Reference Field) temporarily linked to the session id of the user. They can be cleared once consumed on the Appointment form.
But I'd like to ask the community first before creating that custom table: is there any existing ServiceNow functionality or simple plugin that might do this already?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2014 05:09 PM
Option 1 should work, but you will need an onLoad client script to get query string value and set the field. Below is an example:
function onLoad() {
g_form.setValue('loaner', getURLParameter('sysparm_loaner'));
}
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null
}
In the above example, I set a parameter called sysparm_loaner in the button that calls the new form.
Another option you have is to set a session variable. Here is a wiki article with details on how to set, get, and clear them:
Session Client Data - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2014 05:09 PM
Option 1 should work, but you will need an onLoad client script to get query string value and set the field. Below is an example:
function onLoad() {
g_form.setValue('loaner', getURLParameter('sysparm_loaner'));
}
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null
}
In the above example, I set a parameter called sysparm_loaner in the button that calls the new form.
Another option you have is to set a session variable. Here is a wiki article with details on how to set, get, and clear them:
Session Client Data - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2014 08:45 AM
I don't think that your scenario for Option #1 would work as I've already tried that method and it failed.
Between the Incident form which will pass the query string parameter and the Appointment form, there is a Calendar Report of "Available" Appointment slots so that the user can choose which appointment time slot to schedule.
So, even if I have the following URL generated from the Incident form and am passing the query string parameters:
sys_report_display.do?sysparm_report_id=[report_sys_id]&sysparm_loaner=[incident_sys_id]
It will open the Report with the associated Report ID and contain the query string. However, once you click on any button on the Calendar Report (e.g. to change it from a monthly to weekly view, or to change it to the next month, etc.) the query string "sysparm_loaner" gets erased entirely. The Reports are entirely ignorant of any other query-string parameters, so this approach seems brittle to me.
Additionally, to do it properly, I would need to pass that "sysparm_loaner" query string into each of the Appointment form links on the Calendar (e.g. for Nov 5, there is a link to the "Available (9:00 AM - 9:30 AM)" time slot which will take you to the Appointment form for that time slot). I haven't researched how to do this yet, seeing as there was already the problem with the initial query string being erased, but based on my research on the Report wiki, it looks like it would be difficult to do, or require a lot of effort - when really what I need is to set a variable in one place and retrieve it in another.
I will take a look at the Session Client Data that you've suggested - that looks more like it might work and seems to provide a place for Session variables.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2014 06:48 PM
one of the solutions told Michael Ritchie should do the trick... i would go for the first solution using URL we have multiple items using this....