- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2022 09:42 AM
I am trying to update tickets under the tables - sc_task, sc_request and sc_req_item using the script below but apparently only tickets in the 1st table - sc_task got updated while for the other 2 tables, the value is not updated at all..
Mind to let me know why is it not working?
var gr = new GlideRecord('sc_task');
gr.addQuery('contact_type', '');
gr.query();
while (gr.next()) {
gr.setValue('contact_type', 'Self-service');
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.update();
var Request = new GlideRecord('sc_request');
gr.addQuery('contact_type', '');
gr.query();
while (gr.next()) {
gr.setValue('contact_type', 'Self-service');
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.update();
var Req = new GlideRecord('sc_req_item');
gr.addQuery('contact_type', '');
gr.query();
while (gr.next()) {
gr.setValue('contact_type', 'Self-service');
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.update();
}
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2022 09:47 AM
Hi
Plz try this just some code changes
var gr = new GlideRecord('sc_task');
gr.addQuery('contact_type', '');
gr.query();
while (gr.next()) {
gr.setValue('contact_type', 'Self-service');
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.update();
var req = new GlideRecord('sc_request');
req.addQuery('contact_type', '');
req.query();
while (req.next()) {
req.setValue('contact_type', 'Self-service');
req.autoSysFields(false);
req.setWorkflow(false);
req.update();
var req_item = new GlideRecord('sc_req_item');
req_item.addQuery('contact_type', '');
req_item.query();
while (req_item.next()) {
req_item.setValue('contact_type', 'Self-service');
req_item.autoSysFields(false);
req_item.setWorkflow(false);
req_item.update();
}
}
}
Please Mark it correct if its helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2022 10:05 AM
Hi There,
You are updating 3 tables but i dont see any dependency in your code, if there is no dependency (i am predicting to see your code) please try below
Var tab=['sc_task','sc_request','sc_req_item'];
for (var i = 0; i < tab.length; i++) {
var gr = new GlideRecord(tab[i]);
gr.addQuery('contact_type', '');
gr.query();
gr.setValue('contact_type', 'Self-service');
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.updateMultiple();
}
Hope this will help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2022 09:47 AM
Hi
Plz try this just some code changes
var gr = new GlideRecord('sc_task');
gr.addQuery('contact_type', '');
gr.query();
while (gr.next()) {
gr.setValue('contact_type', 'Self-service');
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.update();
var req = new GlideRecord('sc_request');
req.addQuery('contact_type', '');
req.query();
while (req.next()) {
req.setValue('contact_type', 'Self-service');
req.autoSysFields(false);
req.setWorkflow(false);
req.update();
var req_item = new GlideRecord('sc_req_item');
req_item.addQuery('contact_type', '');
req_item.query();
while (req_item.next()) {
req_item.setValue('contact_type', 'Self-service');
req_item.autoSysFields(false);
req_item.setWorkflow(false);
req_item.update();
}
}
}
Please Mark it correct if its helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2022 10:05 AM
Hi There,
You are updating 3 tables but i dont see any dependency in your code, if there is no dependency (i am predicting to see your code) please try below
Var tab=['sc_task','sc_request','sc_req_item'];
for (var i = 0; i < tab.length; i++) {
var gr = new GlideRecord(tab[i]);
gr.addQuery('contact_type', '');
gr.query();
gr.setValue('contact_type', 'Self-service');
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.updateMultiple();
}
Hope this will help you.