Adding Table Data to Drop-down Using AngularJS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2018 10:39 AM
So I am trying to create an addon for one of my widgets and I am trying to target the names of the items from the Business Applications Table and pull them to a drop-down list.
I'm sure I'd have to put a ng-options directive and make a server-side function to pull this information from the table to the drop-down, but I'm not entirely sure.
Can anyone help me? That would be extremely appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2018 01:12 PM
Hello Romare,
What is the specific business requirement? When you say create an addon for a widget, you mean you are editing a custom widget?
To get you started yes, you would use an ng-options, and you would put the glide record in the server script of the widget.
For an example check out the OOB Simple list widget.
Look in particular at how the server script has a glide record that populates data.list (line 99), and then it is called in an ng-repeat in the html with c.data.list (line 13)
You would just pull the data that you need into the ng-options on the form that you created.
Hopefully that helps! Please let me know if you have some more details / specific requirements, and include any of the code that you have tried?
Best,
Andrew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2018 06:42 AM
Hey Andrew,
First I want to say thank you for your reply. I'm pretty new to using ServiceNow this way. The business requirement is to add a drop-down selection to a custom widget which holds the names of the data records in the business applications table.
I haven't thought of using the c.data.list in the HTML, but I have everything else in both HTML. I do appreciate you giving me an example, I'll check it out and see if this will help me.
Here is some code that I've tried so far:
HTML:
<!--Business Service Test Code -->
<label for="serviceSelect">Business Service (Test): </label>
<select name="serviceSelect" id="serviceSelect" ng-model="select" ng-options="name in data.businessService">
</select>
Server
data.businessService = [];
var grBS = new GlideRecord( 'u_business_application.list' );
grBS.query();
while(grBS.next()){
var businessServ = {};
businessServ.name = grBS.getValue('name');
data.businessService.push(businessServ);
}
Thanks,
Romare
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2018 07:09 AM
Hey Romare,
Awesome, glad to hear you are going to check it out. The reason I asked for the business requirement, is because while ServiceNow is capable of doing what you are asking it is a pretty uncommon request.
Typically we try and stay OOB where possible. While ServiceNow can do what you are asking, with a combination of displaying the data and setting up an input on the server script to send the data collected back to the server if needed, we rarely go that route. There is a data table widget that can display the list of Business applications, and when clicked into each record can be seen / edited. There is an OOB simple list widget which may be exactly what you need, which can show a simple list of any record type.
You may have a very valid reason for going with a custom widget, and I am happy to further help you build out the code as you encounter issues, but I just want to ensure that we find the best solution to your business problem and understand the 'why' before the 'what' and jumping into relatively complex custom code
If you do want to just dive into code though feel free to post a run down of what you have tried with some screen shots if you run into any issues!
Best,
Andrew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2018 07:28 AM
Hey Andrew,
I see, I never thought of it like that before. I know I've been racking my head around this for about a week or so now. I figured taking a shot at asking the community would help, even if it was a tiny bit. With your help that remains true. I copy/pasted some code in my previous reply if you haven't seen it.
Thanks again,
Romare