- 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-15-2024 11:59 PM
Hi,
Could you please clarify your question.
A sysID is in fact a string, it's a 32bit unique identifier, for more info, you can read on the Docs.
What did you expect to get ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 12:04 AM
@OlaN thanks for reply.
I checked one example records after I run the script and its put the display name into the reference field and not the sys_id.
The field is empty but the xml show me that something is in the field.
I expect to see the sys_id in the u_leistunggschein field and not the display name?
Thanks for your help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 12:16 AM
Sorry, still hard to understand your issue.
But you can start off by avoiding the classic pass-by-reference issue.
Change your code to use getters and setters. Like below.
// change this type of code
var leistungsscheinValue = tsoLookupGR.u_leistungsschein;
// into this
var leistungsscheinValue = tsoLookupGR.getValue('u_leistungsschein');
// and change this type of code
taskSlaGR.u_leistungsschein = leistungsscheinValue;
// into this
taskSlaGR.setValue('u_leistungsschein', leistungsscheinValue);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 02:46 AM
I changed the script. Still same behavior.
(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('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.setValue('u_leistungsschein', leistungsscheinValue);
taskSlaGR.update();
}
}
}
})();
The first screenshot shows that the "u_leistungsschein" reference field contains a value but lacks a corresponding sys_id. After running the script, the field should display both the value and the sys_id, similar to how it was manually done by me. see screenshot ->
and here After I run the script I can group by "u_leistungsschein" I find the records bot there is no Reference in the field. Becasue I think of missing sys_id.