- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2019 09:21 AM
I have Data Table From Instance Definition (table = incident) and widget-form on a page.
the incident displays in the form widget.
I would like the Data Table From Instance Definition to display in a different widget on the page.
How do I tell Data Table From Instance Definition to display in that other widget?
Solved! Go to Solution.
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 05:23 AM
Hi,
If the form has the fields, then you don't nee dto add any code. The widget will take care of the update. I already checked this.
How did you add a field to the form? You need to add a field to the Service portal view as that is the view that gets rendered in the from widget.
And any changes to any of the fields that are displayed in the form will be updated by the widget itself. The code that i give is to update any other fields that are not on the form.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2019 06:33 AM
If your widget is a static widget and not dependent on the incident, then find out the page_id in which the incident is being displayed and go to service now portal configuration -> designer-> select page and drag your widget in that page.
Then for each incident that widget will be visible.
If your widget has to show dynamic data based on the incident selected, then you need to do some coding in your widget.
The process of showing the widget is still the same as above, but the content in the widget will change based on the incident sys_id.
For this, you need to capture the url in the server script, like this
if(input) {
var results = [];
var url = input.url;
var sSysID_pos = url.indexOf("sys_id");
sSysID_pos=sSysID_pos+7;
var IncSysID = url.substr(sSysID_pos,32);
}
The above code gives you the incident sys_id. Based on that you write your logic of what data you need to change.
Mark the comment as a correct answer and also helpful if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2019 06:48 AM
I have widget 1: Data Table From Instance Definition where I specify table = incident (it is a clone)
I have widget 2: form_clone cloned from widget-form.
example 1: If I have both on the page (page_id = myPage) the incident displays in the form widget.
example 2: if I remove form_clone from the page the incident displays in a new window.
My question is why does incident display in form_clone in example 1?
what is telling widget 1 that it should display in widget 2?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 01:25 AM
Hi,
If i understand correctly, you mean to say that when you click on incident in the data table, the incident is shown in the other widget which is form_clone and that is present in the same widget.
The widget knows which incident to display, because it reads the sys_id from the url. If you look at the server script of form widget, you will see the following code snippet through which it takes the incident and shows.
if (input) {
data.table = input.table;
data.sys_id = input.sys_id;
data.view = input.view;
var result = {};
Mark the comment as a correct answer and also helpful if it answers your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 03:02 AM
thank you! I did not know what that piece of code was doing.
just to be clear: you mean to say that when you click on incident in the data table, the incident is shown in the other widget which is form_clone and that is present in the same widget >> they are on the same PAGE, 2 different widgets
I could use further help!
How does the data that is input get saved to the database? I know it must go into the data object. in my other widgets, the server and client script has code like shown below which i understand (like the oob add-widget).
The form widget does not and I do not understand how the input data gets into the database.
my other widget has:
server script:
var gr = new GlideRecord('incident');
gr.initialize();
gr.setValue('short_description', input.short_description);
gr.insert();
client script has a function to call server.update()
c.submit = function() {
c.server.update().then(function(response) {
$rootScope.$broadcast('$sp.widget-close-modal');
});
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 04:37 AM
Hi,
The form widget is mainly used to fetch the data based on sys_id and show it in the form. And the piece of code that i shared actually does that.
And the saving part of the code is right below that code in the form widget server scirpt.
data.table = input.table;
data.sys_id = input.sys_id;
data.view = input.view;
var result = {};
if (input._fields) {
result = $sp.saveRecord(input.table, input.sys_id, input._fields);
data.sys_id = result.sys_id;
}
Mark the comment as a correct answer and also helpful if this answers your question.
Mark the comment as a correct answer and also helpful if this helps.