Pull a record from Remote table and add field values to a custom widget.

Afsar2
Tera Contributor

Hi,

Idea is to leverage on Remote Tables.

I am trying to fetch weather related data from an opensource API and create a record in remote table.

I am able to populate the remote table with weather details based on session user's location.

I want to pull this details into custom widget.

The server script in custom widget is not able to fetch glide record from remote table.

Same GlideRecord script is able to fetch data from other tables but fails for Remote Tables.

Any suggestions?

 

Regards,

Afsar Sheikh

 

10 REPLIES 10

Hi Afsar,

I tried to reproduce this issue. I created one remote table in scoped application and tried to access it using GlideRecord query.

find_real_file.png

find_real_file.png

 

It worked as expected.

find_real_file.png

I have created it with below permissions:

find_real_file.png

 

Also created one definition record. If I deactivate definition then it throws an error.

find_real_file.png

If I activate definition and comment the script which was adding dummy records then it returns zero record.

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi,

Please check below examples, how external source is used to get data and use v_table.addRow() to add records.

These records will be available when you make GlideRecord query.

https://docs.servicenow.com/bundle/rome-servicenow-platform/page/administer/remote-tables/reference/...

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

shloke04
Kilo Patron

Hi,

Please follow the steps below to achieve your requirement:

This is working for me and tested in my PDI instance.

1) I have created a new Remote Table in a Custom Scope as needed as shown below where I have two field Name and Short Description created as shown below:

find_real_file.png

2) Now once you have created the Remote table, next step is to create a Definition for the Remote Table. Navigate to the module "Definition as shown below:

find_real_file.png

3) Click on New button and say add your script which you want to insert data into this Remote Table. I have created a demo sample script so that a record gets inserted into this Remote Table as shown below:

Script:

(function executeQuery(v_table, v_query) {
   
	var rec = {};
	rec.sys_id = '23456';
	rec.u_name = 'System Admin';
	rec.u_short_description = 'this si for community helping users';
	v_table.addRow(rec);
	
  })(v_table, v_query);

find_real_file.png

Output 1:

Data inserted into my Remote Table as shown below:

find_real_file.png

Now in order to show this data into Service Portal, you do not need to create a Custom widget here and would suggest to make use of OOB capability which allows you to do the same job:

1) Navigate to Page module under Service portal Application menu as shown below:

find_real_file.png

Now open the page where you need to add the widget to display the data, I have created a new page in my custom scope as shown below:

Click on Open in Designer as shown below after opening your Page record:

find_real_file.png

Now add this widget in the container where you need to add "Data Table from Instance Definition"

find_real_file.png

Now once this widget is added, Navigate to widget module and open this widget as shown below: "Data Table from Instance Definition"

find_real_file.png

find_real_file.png

After opening the widget record scroll down to "Instance" related list as shown below:

find_real_file.png

Now open the record where title is blank and select your table Name i.e. Remote Table Name with fields as shown below:

find_real_file.png

Once this is done, Navigate to your portal page and result are as you need:

Result:

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Afsar2
Tera Contributor

Hi @shloke04 ,

 

I really appreciate your help.

I was able to add row to remote table and fetch in a custom widget  in service portal.

Soon I'll be posting an article with the details about the task.

 

Thank you.

Hi Afsar,

Glad your query is resolved. Can you mark my answer as correct and close this thread for other.

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke