- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 11:47 PM
Hi everyone,
I have a fix script. But the variable "serviceKomponente" give me a string back. And I need the sys-id becasue the field "u_leistungschein" is a reference field.
(function() {
// Initialize GlideRecord for the u_dl_tso_lookup table
var tsoLookupGR = new GlideRecord('u_dl_tso_lookup');
tsoLookupGR.query();
// Iterate over each record in the u_dl_tso_lookup table
while (tsoLookupGR.next()) {
// Get the current value of u_leistungsschein from the u_dl_tso_lookup record
var leistungsscheinValue = tsoLookupGR.u_leistungsschein;
var primaereServicekomponenteValue = tsoLookupGR.u_primaere_servicekomponente.toString(); // Convert list field to string
// Split the list field into individual values
var serviceKomponenten = primaereServicekomponenteValue.split(',');
// Iterate over each service component
for (var i = 0; i < serviceKomponenten.length; i++) {
var serviceKomponente = serviceKomponenten[i].trim();
// Find the corresponding task_sla records by matching service_offering of the related task
var taskSlaGR = new GlideRecord('task_sla');
taskSlaGR.addQuery('task.service_offering', serviceKomponente);
taskSlaGR.query();
// Update the u_leistungsschein field in the task_sla table
while (taskSlaGR.next()) {
taskSlaGR.u_leistungsschein = leistungsscheinValue;
taskSlaGR.update();
}
}
}
})();
WHat I need to adapt here?
Thanks for your help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2024 12:44 AM
(function() {
// Initialize GlideRecord for the u_dl_tso_lookup table
var tsoLookupGR = new GlideRecord('u_dl_tso_lookup');
tsoLookupGR.query();
// Iterate over each record in the u_dl_tso_lookup table
while (tsoLookupGR.next()) {
// Get the current value of u_leistungsschein from the u_dl_tso_lookup record
var leistungsscheinValue = tsoLookupGR.getValue('sys_id');
//gs.addInfoMessage(leistungsscheinValue);
var primaereServicekomponenteValue = tsoLookupGR.u_primaere_servicekomponente.toString(); // Convert list field to string
//gs.addInfoMessage(primaereServicekomponenteValue);
// Split the list field into individual values
var serviceKomponenten = primaereServicekomponenteValue.split(',');
// Iterate over each service component
for (var i = 0; i < serviceKomponenten.length; i++) {
var serviceKomponente = serviceKomponenten[i].trim();
//gs.addInfoMessage(serviceKomponente);
// Find the corresponding task_sla records by matching service_offering of the related task
var taskSlaGR = new GlideRecord('task_sla');
taskSlaGR.addQuery('task.service_offering.sys_id', serviceKomponente);
taskSlaGR.query();
// Update the u_leistungsschein field in the task_sla table
while (taskSlaGR.next()) {
taskSlaGR.setValue('u_leistungsschein', leistungsscheinValue);
taskSlaGR.update();
}
}
}
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 04:24 AM
It seems the values you get from the list are not SysIDs, but rather string fields of manually entered data perhaps?
A list can contain both SysIDs, and manually entered data (depending on how it's setup).
So I would advice to double check the data, and check that it's a valid record before updating the record with the new value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 11:42 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 12:03 AM
Hi @JohnDF ,
refer this:
(function() {
// Initialize GlideRecord for the u_dl_tso_lookup table
var tsoLookupGR = new GlideRecord('u_dl_tso_lookup');
tsoLookupGR.query();
// Iterate over each record in the u_dl_tso_lookup table
while (tsoLookupGR.next()) {
// Get the current value of u_leistungsschein from the u_dl_tso_lookup record
var leistungsscheinValue = tsoLookupGR.u_leistungsschein;
var primaereServicekomponenteValue = tsoLookupGR.u_primaere_servicekomponente.toString(); // Convert list field to string
// Split the list field into individual values
var serviceKomponenten = primaereServicekomponenteValue.split(',');
// Iterate over each service component
for (var i = 0; i < serviceKomponenten.length; i++) {
var serviceKomponente = serviceKomponenten[i].trim();
// Find the corresponding task_sla records by matching service_offering of the related task
var taskSlaGR = new GlideRecord('task_sla');
taskSlaGR.addQuery('task.service_offering', serviceKomponente);
taskSlaGR.query();
// Update the u_leistungsschein field in the task_sla table
while (taskSlaGR.next()) {
// Retrieve the sys_id of the u_leistungsschein record
var leistungsscheinGR = new GlideRecord('u_leistungsschein');
if (leistungsscheinGR.get('name', leistungsscheinValue)) { // Assuming 'name' is the field that matches leistungsscheinValue
taskSlaGR.u_leistungsschein = leistungsscheinGR.sys_id; // Assign the sys_id to the reference field
taskSlaGR.update();
} else {
gs.error('u_leistungsschein record not found for value: ' + leistungsscheinValue);
}
}
}
}
})();
……………………………………………………………………………………………………
Please Mark it helpful👍 and Accept Solution✔️!! If this helps you to understand.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 02:53 AM
Hi @Satishkumar B thanks for reply.
new GlideRecord('u_leistungsschein');
I have no table name like this. "u_leistungsschein" is a field on the "task_sla" table and "u_dl_tso_lookup" table to do the reference on both tables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2024 12:44 AM
(function() {
// Initialize GlideRecord for the u_dl_tso_lookup table
var tsoLookupGR = new GlideRecord('u_dl_tso_lookup');
tsoLookupGR.query();
// Iterate over each record in the u_dl_tso_lookup table
while (tsoLookupGR.next()) {
// Get the current value of u_leistungsschein from the u_dl_tso_lookup record
var leistungsscheinValue = tsoLookupGR.getValue('sys_id');
//gs.addInfoMessage(leistungsscheinValue);
var primaereServicekomponenteValue = tsoLookupGR.u_primaere_servicekomponente.toString(); // Convert list field to string
//gs.addInfoMessage(primaereServicekomponenteValue);
// Split the list field into individual values
var serviceKomponenten = primaereServicekomponenteValue.split(',');
// Iterate over each service component
for (var i = 0; i < serviceKomponenten.length; i++) {
var serviceKomponente = serviceKomponenten[i].trim();
//gs.addInfoMessage(serviceKomponente);
// Find the corresponding task_sla records by matching service_offering of the related task
var taskSlaGR = new GlideRecord('task_sla');
taskSlaGR.addQuery('task.service_offering.sys_id', serviceKomponente);
taskSlaGR.query();
// Update the u_leistungsschein field in the task_sla table
while (taskSlaGR.next()) {
taskSlaGR.setValue('u_leistungsschein', leistungsscheinValue);
taskSlaGR.update();
}
}
}
})();