- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 01-30-2018 12:58 PM
I just had a requirement on an order guide to pass variable values between forms and wanted to share the solution I came up with. There is Cascading Variables that can be used on order guides, which will pass data across order guide forms, but that wouldn't work for my requirements here for the following reason:
- In order for cascading variables to be passed on to other forms, those variables have to be filled in on the "Describe Needs" page of the order guide.
One of my requirements was to clean up this order guide and try to limit it down to only checkboxes on the first page that a user would need to check and then fill out their data on any of the subsequent forms they had selected with the checkboxes.
I tried creating a variable set that was hidden on the "Describe Needs" page, then visible on some of the other forms, but this didn't work though, because even if the fields get filled in on one form, when the next form that had the same variable set gets loaded, none of that data that was filled in from the previous form came through with it. It all came back to needing those fields to be filled in on the first "Describe Needs" page. So what to do...
There's actually a really easy way to do this, but you kind of have to go outside of Servicenow to do it. The way that I was able to do this was by leveraging browser storage, which functions very similarly to the Servicenow scratchpad.
You can find information on Web Storage here: HTML5 Web Storage
So, on the order guide form that has the data that you want to pass on, you'll need to create a client script that assigns values to either a localStorage or sessionStorage variable. My advice is to use sessionStorage as these variables will get cleared out whenever a user closes out of the browser tab it was stored on, localStorage variable types have no expiration date and can live on forever.
Here's an example of the onChange client script I used on one of the order guide forms to push data up to the browser:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
//Get the field values
var var1 = g_form.getValue('variable1');
var var2 = g_form.getValue('variable2');
var var3 = g_form.getValue('variable3');
var var4 = g_form.getValue('variable4');
//clear out any values that had been previously stored in the browser
sessionStorage.variable1 = '';
sessionStorage.variable2 = '';
sessionStorage.variable3 = '';
sessionStorage.variable4 = '';
//Store new values in the browser
sessionStorage.variable1 = var1;
sessionStorage.variable2 = var2;
sessionStorage.variable3 = var3;
sessionStorage.variable4 = var4;
}
Then, on any other forms in your order guide where you want to apply the data you've stored in the browser, just create an onLoad client script that pulls that data down. Example:
function onLoad() {
//check to see if variable info is already stored in the browser
if (sessionStorage.variable1) {
//Get the field values
var var1 = sessionStorage.variable1;
var var2 = sessionStorage.variable2;
var var3 = sessionStorage.variable3;
var var4 = sessionStorage.variable4;
//Set the field values
g_form.setValue('variable1', var1);
g_form.setValue('variable2', var2);
g_form.setValue('variable3', var3);
g_form.setValue('variable4', var4);
}
}
I also have an onSubmit script on the order guide that clears the stored browser data. The reason for this, is that I'm using this browser storage method for an on-boarding form and whomever is filling out the form may end up going back to fill out other on-boarding forms, without closing the tab they are currently on. So just to make sure they don't end up pulling values they stored from their last form, I clear it out. Here's my onSubmit script:
function onSubmit() {
sessionStorage.variable1 = '';
sessionStorage.variable2 = '';
sessionStorage.variable3 = '';
sessionStorage.variable4 = '';
}
That's all there is to it. As you can see, it's super easy to overcome Servicenow's limitations with cascading variables and order guides. Let me know what you think.
- 2,579 Views