Robust Transform Map - RTE Entity script Operation Not working

Nilanjan1
Mega Sage

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);

 

9 REPLIES 9

Pratik Malviya
Tera Guru

Hi @Nilanjan1 ,

Instead of 

output[i] = grPC.sys_id;

Try

output[i] = grPC.getUniqueValue();
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Thanks,
Pratik Malviya

James Chun
Kilo Patron

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

@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 ? 

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