Robust Transform Map - RTE Entity script Operation Not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2024 02:47 AM
Dear Experts,
Can someone guide me on why the assigned to value is not being set in a Robust transform Map when used with Script operations on RTE Entity.
I am trying to set the values as per the source
if the source is empty, the assigned to and managed by should be empty
if the source has a value, the assigned to and managed by should be left as is.
I need some help urgently.
The code is attached below
(function(batch, output) {
// add your code here.
for (var i = 0; i < batch.length; i++) {
//step1: access the input variables
var a = batch[i].input; //Value of the source field.
var grPC = new GlideRecord('sys_user');
grPC.addQuery('correlation_id', a);
grPC.query();
if (grPC.next()) {
output[i] = grPC.sys_id;
}else{
output[i] = NULL;
}
}
})(batch, output);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2024 10:52 AM
Hi @Nilanjan1 ,
Instead of
output[i] = grPC.sys_id;
Try
output[i] = grPC.getUniqueValue();
Thanks,
Pratik Malviya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2024 12:02 PM
Hey @Nilanjan1 ,
I don't think there is a column called 'correlation_id' in the User [sys_user] table, unless I am mistaken.
Is the value of the input (i.e. batch[i].input) a sys_id of an User record? If so, you can replace line 7 - 9 of your code with the following
grPC.get(a);
if(grPC.isValidRecord()){
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 04:37 AM
@James Chun it started to work for the user name when the replaced the query from the correlation Id to the user name, but I have to use the same concept for the cost center, department and location. Is this the rigth way to use it.
(function(batch, output) {
// add your code here.
for (var i = 0; i < batch.length; i++) {
//step1: access the input variables
var a = batch[i].input; //Value of the source field.
var costCenter = new GlideRecord('cmn_cost_center');
costCenter.addQuery('name', a);
costCenter.query();
if (costCenter.next()) {
output[i] = costCenter.sys_id;
} else {
output[i] = null;
}
}
Can you quickly help on this ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 11:35 AM
Hi @Nilanjan1,
That looks good, just make sure the attribute you are querying with (e.g. 'name' in the script above), will be unique. Otherwise, you may end up with incorrect records.
Thanks