
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2018 11:02 AM
Hi guys,
I'm relatively new to Servicenow (I've been working on it around 4 months). I have a client who wants to update the vulnerable item table which contains a reference field to the vulnerability entries table. He wants to add some fields of that table (vulnerability entries) on this form, however that table in conformed of records of two tables that extend from it: Third party vulnerability entries and National Database vulnerability entries, both with different fields that resemble similar information.
Third party vulnerable entry: Summary, Severity, Threat, Solution
National DB vulnerable entry: Summary, Vulnerability score.
I was thinking I could add a few string fields and just populate them with the correct info depending on whether the record is from National DB vul. entry or Third party. vul. entry using a script, those fields will be read only for everybody anyway so there's no need to update anything on the original records. I was wondering if there's a way of adding those fields on the vulnerable Item form so I can populate them On Load/On change without actually adding them to the table.
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2018 11:30 AM
I don't know of a way to add string fields to a form that aren't stored in the table, but there are a couple of ways to get something similar.
The easiest way, since these are reference fields, is to use the form layout (not the form designer) and you can add in fields from related tables. Open the vulnerable item form, click the additional actions icon at the top and choose Configure -> Form Layout from the menu. This will bring up a list of Available and Selected fields. In the available list highlight the reference field you want to get more information about and an icon will be added that says "Expand selected reference field" in between the Available and Selected boxes. If you press that, it will change the Available box to show all the fields on the referenced table. You can then highlight those fields and press the '>' button that moves the field to the Selected box. You can then use the up and down arrows to move the field to where you want it on the form.
The other way is to use an annotation on the form with a script. Using the form layout tool, you select the * Annotation item from the Available list and move it to the selected box where you want the annotation to be. Highlight the annotation in the selected box and you can choose what type of annotation you want. You will have to try the different annotation styles to see which one you want for this application. If you set the annotation to include HTML, you can put <span id="myid"></span> into the annotation. Then you can use an onload client script to update the span using:
document.getElementByID('myid').innerHTML='enter your HTML code here';
I would recommend also using a display business rule to get the information you want from the other tables and adding it to the g_scratchpad object to eliminate an extra round trip to the server. Then you can use the info in the g_scratchpad object in your client script to update your annotation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2018 11:30 AM
I don't know of a way to add string fields to a form that aren't stored in the table, but there are a couple of ways to get something similar.
The easiest way, since these are reference fields, is to use the form layout (not the form designer) and you can add in fields from related tables. Open the vulnerable item form, click the additional actions icon at the top and choose Configure -> Form Layout from the menu. This will bring up a list of Available and Selected fields. In the available list highlight the reference field you want to get more information about and an icon will be added that says "Expand selected reference field" in between the Available and Selected boxes. If you press that, it will change the Available box to show all the fields on the referenced table. You can then highlight those fields and press the '>' button that moves the field to the Selected box. You can then use the up and down arrows to move the field to where you want it on the form.
The other way is to use an annotation on the form with a script. Using the form layout tool, you select the * Annotation item from the Available list and move it to the selected box where you want the annotation to be. Highlight the annotation in the selected box and you can choose what type of annotation you want. You will have to try the different annotation styles to see which one you want for this application. If you set the annotation to include HTML, you can put <span id="myid"></span> into the annotation. Then you can use an onload client script to update the span using:
document.getElementByID('myid').innerHTML='enter your HTML code here';
I would recommend also using a display business rule to get the information you want from the other tables and adding it to the g_scratchpad object to eliminate an extra round trip to the server. Then you can use the info in the g_scratchpad object in your client script to update your annotation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2021 10:12 AM
This solution should work however I am getting the error message Cannot read property 'getElementById' of null. I believe this may be due to direct DOM access being disabled.
I see the message at the top of the form layout edit window that says
"New client-scripts are run in strict mode, with direct DOM access disabled. "
Even after setting the Isolated script flag I get the same message.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2018 11:44 AM
Thanks Steve. Well, it wouldn't be possible by using "configure -> form layout" (that's what I was using) as these fields are not exclusive of the referenced table (vlnerability entry), they are on the child tables (Third party Vul. entry and National DB. vul. entry) so it won't show those fields even by "dot walking" there. I'll try the annotation option, thanks for the idea! I'll let you know how it goes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2018 12:12 PM
If it is a direct reference from one table to another you should be able to "dot walk" there. I've done it on a number of tables. If it is in a related list that could have multiple records it won't work. I'm not sure the exact relationship on the vulnerabilities tables, I haven't gotten dragged into the security world yet, but here is an example of how you could use it on the User table.
On the form for the User table you could get the address from the location table and display that on the user form by dot walking. You have to highlight the location field on the form layout and hit the expand button in the middle like in the screenshot below. After the Available list is updated, select the address field from the available list and move it to the Selected box. Then anytime you load a user record it will immediately pull in the address from the location table.
Now you wouldn't be able to add in fields from incidents related to the user as form fields, because the incident form references the user table, not the other way around.
As a word of warning, you may also want to add in some UI Policies to set the related fields to read only. Otherwise users may accidentally edit the fields on the referenced records without being aware of it. If they don't have write access to the reference field they can't edit it anyway, but it can be a concern.