Advertisement
Guest User

Untitled

a guest
Jul 9th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. UI Form Upload Test Page
  2. The Instructions
  3.  
  4. WARNING: This is a filthy dirt hack. Do NOT try this at home.
  5. 1. Get Creative
  6. 2. Create a New UI Page - upload_test_ui_page
  7. a. HTML Section
  8. i. Generate a 32 character string for a unique ID on every page load, use MD5(userID+now(),32) or some such thing.
  9. ii. include the SaveAttachment UI macro
  10. iii. Build your form
  11. iv. Add an upload link
  12. b. Processing Section
  13. i. create the record - pass the generated sys_id to the processing script
  14. ii. correct the attachment - update the atatchment tabel with the tabela adn sys_id of the created record.
  15. iii. redirect to new record
  16. 3. Service Catalog Item
  17. a. Content Type: External Content
  18. b. Target: Within Catalop
  19. c. URL: upload_test_ui_page.do
  20. 4. Happy Dance!
  21.  
  22. The Explanation
  23. This is less effective from a business rule, client script, UI policies perspective but the effect for the end user is far superior.
  24. 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.
  25. 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.
  26.  
  27. The Credits
  28. Shawn Wu - swu2@central1.com or shawu127@gmail.com - for his diligent implementation, testing and trouble shooting.
  29. Ryan Fraser - ryan.fraser@servicenow.com - for pointing me the right direction when I couldn't figure this out in the first place.
  30. Jon Crane - Jon.Crane@servicenow.com - for suggesting this wackiness as a possible approach.
  31. AJ Simpkin - asimpkin@central1.com or aj@grayscale.ca - for being dumb enough to even think this up in the first place.
  32.  
  33. #####
  34.  
  35. From: Jon Crane [mailto:Jon.Crane@servicenow.com]
  36. Sent: Wednesday, 08 April, 2015 15:29
  37. To: AJ Simpkin
  38. Subject: Re: UI Page Attachments
  39. Awesome. Nice work with the UI page..
  40. 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…
  41. Add this to your UI page:
  42. <a onclick="saveMyAttachments()"><img width="16" height="16" border="0" src="images/icons/attachment.gifx" />click here to manage your attachments</a>
  43. In the Client script portion, add
  44. function saveMyAttachments() {
  45. saveAttachment('incident', << Sys ID has to go here...>>);
  46. }
  47. 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.
  48. 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:
  49. GlideSysAttachment.copy('sourcetable', 'sys_id', 'destinationtable', 'sys_id');
  50. Here is my pseudo-order of operations
  51. • Load awesome UI page
  52. • Fill out said awesome UI page
  53. • Click the attachment button at the bottom
  54. • On click, do the following
  55. • Generate a fake GUID
  56. • Pass the GUID to the saveAttachment() script
  57. • Submit the form
  58. • Processing script inserts record
  59. • 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