Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UI Form Upload Test Page
- The Instructions
- WARNING: This is a filthy dirt hack. Do NOT try this at home.
- 1. Get Creative
- 2. Create a New UI Page - upload_test_ui_page
- a. HTML Section
- i. Generate a 32 character string for a unique ID on every page load, use MD5(userID+now(),32) or some such thing.
- ii. include the SaveAttachment UI macro
- iii. Build your form
- iv. Add an upload link
- b. Processing Section
- i. create the record - pass the generated sys_id to the processing script
- ii. correct the attachment - update the atatchment tabel with the tabela adn sys_id of the created record.
- iii. redirect to new record
- 3. Service Catalog Item
- a. Content Type: External Content
- b. Target: Within Catalop
- c. URL: upload_test_ui_page.do
- 4. Happy Dance!
- The Explanation
- This is less effective from a business rule, client script, UI policies perspective but the effect for the end user is far superior.
- When you step away from the core platform you have to bake a lot of this on your own... and having done so for our users we lost the ability to upload attachments with the platform.
- I am not sure how ServiceNow is doing this behind the red curtain but I'm pretty sure the approach will be similar. The SaveAttachment UI Macro requires a table and record ID so that when you upload the attachment it has a reference once it has completed the write to the database. When you upload an attachment to the catalog item you don't have a record so they must be using an on-the-fly sys_id approach to keep it aligned with the users input and then play catch up after submit. In this example we are creating an incident record and using the incident table and a fake ID to manage the attachments. So long as you pass the sys_id to the processing script you are good to go. After you create the INC and get your real sys_id, replace the fake sys_id in the sys_attachment table via script and the attachments will appear with your new INC record.
- The Credits
- Shawn Wu - swu2@central1.com or shawu127@gmail.com - for his diligent implementation, testing and trouble shooting.
- Ryan Fraser - ryan.fraser@servicenow.com - for pointing me the right direction when I couldn't figure this out in the first place.
- Jon Crane - Jon.Crane@servicenow.com - for suggesting this wackiness as a possible approach.
- AJ Simpkin - asimpkin@central1.com or aj@grayscale.ca - for being dumb enough to even think this up in the first place.
- #####
- From: Jon Crane [mailto:Jon.Crane@servicenow.com]
- Sent: Wednesday, 08 April, 2015 15:29
- To: AJ Simpkin
- Subject: Re: UI Page Attachments
- Awesome. Nice work with the UI page..
- Ok, I definitely see your problem. In order to attach any type of file, you need to associate that attachment with a record. I don’t have a definitive solution but this may get your started on the right path…
- Add this to your UI page:
- <a onclick="saveMyAttachments()"><img width="16" height="16" border="0" src="images/icons/attachment.gifx" />click here to manage your attachments</a>
- In the Client script portion, add
- function saveMyAttachments() {
- saveAttachment('incident', << Sys ID has to go here...>>);
- }
- saveAttachment() pops up a dialog to manage attachments on any record. Now here’s the rub… you need, as you said, a Sys ID in order to add an attachment.
- What if you generate a ‘fake’ Sys ID and add the attachment to that sys ID. Store your fake Sys ID in a global variable where you can access it later (window.myvariable = myFakeSysId)? In the processing script, after you insert your record, take the sys_id of the NEW record and update the attachment(s) pointing to the FAKE sys_id. Update the records and hope for the best. ;) There’s also a function called GlideSysAttachment. It can handle updating attachments pretty easily. Here’s how it works from the wiki:
- GlideSysAttachment.copy('sourcetable', 'sys_id', 'destinationtable', 'sys_id');
- Here is my pseudo-order of operations
- • Load awesome UI page
- • Fill out said awesome UI page
- • Click the attachment button at the bottom
- • On click, do the following
- • Generate a fake GUID
- • Pass the GUID to the saveAttachment() script
- • Submit the form
- • Processing script inserts record
- • Take the Sys ID of the new record, and update the attachments to the new sys id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement