Scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 01:53 AM
Write an example of a GlideRecord script to retrieve all records from a table called "incident" where the status is "New". is it right?
var gr = new GlideRecord('incident');
gr.addQuery('state', '1');
gr.query();
while (gr.next()) {
gs.print('Incident Number: ' + gr.getValue('number') + ' - State: ' + gr.getValue('state'));
}
GlideRecord is a class that allows interaction with tables (in this case, the "incident" table), enabling queries and manipulation of records. In the provided example, "GlideRecord" is used to retrieve incidents with the value "1" associated with the "State" "New". A variable gr is created using the GlideRecord class to interact with the database table. The addQuery('state', '1') method is used to filter incidents where the state equals "1". The query() method executes the actual query to retrieve records that meet the condition.
The while (gr.next()) loop iterates through all records retrieved by the query. For each record, the code executes gs.print('Incident Number: ' + gr.getValue('number') + ' - State: ' + gr.getValue('state')), which prints the incident number and the state associated with the incident. The getValue() method is used to retrieve specific values from the "number" (incident number) and "state" (incident state) columns.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 06:41 AM
Hi @Sofvrg ,
Yes it is correct.
Regards,
Nikhil Bajaj
Regards,
Nikhil Bajaj