- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2018 06:40 PM
I'm looking for a simple way to pass a variable between forms so that the variable value is set onSubmit of the first form and is read onLoad of the second form. Totally new to ServiceNow and javaScripting so, after reading dozens of posts and following dozens of suggested links in those posts, I'm still coming up empty handed. In VB, you'd simply declare a global variable and call it when needed. Not sure what the counterpart is in JavaScript. Any help you can provide would be appreciated -- especially if you have a code snippet that you've used to do this in the past.
Thanks in advance for your help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2018 06:02 AM
Ah I see. Then I would say the UI Action is a good bet.
If you just want to create a record populating the one field with the one field from the current record is perform a glide record script before the current.update().
Something like this:
var pvg_patient = new GlideRecord('pvg_patients'); // of course replace with the real name of the table
pvg_patient.client_number = current.client_number;
pvg_patient.insert();
current.update();
action.setRedirectUrl(pvg_patient); //redirects them to the "PVG Patients" form
action.setReturnUrl(current); //puts the previous form in this case 'PVG Client' form on the stack
And that should do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2018 08:16 PM
Nope, string for client_number on PVG Client should be fine. I've created 2 custom tables similar to yours, and just referenced the first table on the second table. Should work even with the OOB button.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2018 08:26 PM
Thanks Alyssa. I have it working fine with client_number being a string on both forms.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2018 03:54 AM
Hi Mike,
My question is: Will the process always be that when a 'PVG Clients' form is filled out and submitted, will a 'PVG Patients' form need to be created as well?
If the answer to that is yes, then why not create a Business Rule on the "PVG Clients" table that creates a 'PVG Patients' record after the insert of the 'PVG Clients' record?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2018 05:02 AM
Thanks Chris, that sounds like an interesting approach but, since I'm new to ServiceNow scripting, I'm not clear on how that would work. Wouldn't the issue still be in getting whatever client_number was entered on the PVG Client form into the new PVG Patient record? Or, is there a way to provide a value for a particular field when creating that new record in the PVG Patients table? (The PVG Patient record has about 50 fields and the only one that needs to be filled in on creation is the client_number field.) I'll poke around with this some more to see what I can figure out but if you can provide any additional guidance, it would be much appreciated. Thanks again for the insight.
Also, since each client can have multiple patients, we'd still need a way to create those new patient records with the client number of the 'parent' form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2018 06:02 AM
Ah I see. Then I would say the UI Action is a good bet.
If you just want to create a record populating the one field with the one field from the current record is perform a glide record script before the current.update().
Something like this:
var pvg_patient = new GlideRecord('pvg_patients'); // of course replace with the real name of the table
pvg_patient.client_number = current.client_number;
pvg_patient.insert();
current.update();
action.setRedirectUrl(pvg_patient); //redirects them to the "PVG Patients" form
action.setReturnUrl(current); //puts the previous form in this case 'PVG Client' form on the stack
And that should do it.