Reference field map failed in transform map.

Jyoti Ranjan Se
Tera Contributor

I have wrote this code for checking the value in target table is it present or not .but its only check the first condition and rest of showing me error message

when i put the  correct record for insert it ignore the record

  

 

var approverName = source.getValue('u_approver');
if (action == 'insert' && JSUtil.notNil(source.u_approver)) {
var gr = new GlideRecord('u_epi_approvers');
gr.addQuery('u_name',source.u_approver);
gr.query();
if (!gr.next()) {
ignore = true;
log.error('approver'+''+ approverName+' '+'is not found ');
}
}
//log.error('approver'+''+ approverName+' '+'is not found ');
var type1 = source.getValue('u_type');
if (action == 'insert' && JSUtil.notNil(source.u_type)) {
var Gr = new GlideRecord('u_choice_1');
Gr.addQuery('u_type',source.u_type);
Gr.query();
if (!Gr.next()) {
ignore = true;
log.error('type '+' '+type1 +' '+'is not found ');
}
}
})(source, map, log, target);

 

 

thanks

jyoti

 

 

5 REPLIES 5

Hi Jyoti,

Here's the script that can help you with an AND condition i.e. to check if both Approver and Type are not available in your queried records:

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    // Add your code here
    var approverName = source.getValue('u_approver');
	var approverFlag = true;
    if (action == 'insert' && JSUtil.notNil(source.u_approver)) {
        var gr = new GlideRecord('u_epi_approvers');
        gr.addQuery('u_name', source.u_approver);
        gr.query();
        if (!gr.next()) {
            //ignore = true;
            log.error('approver' + '' + approverName + ' ' + 'is not found ');
			approverFlag = false;
        }
    }
    //log.error('approver'+''+ approverName+' '+'is not found ');
	var typeFlag = true;
    var type1 = source.getValue('u_type');
    if (action == 'insert' && JSUtil.notNil(source.u_type)) {
        var Gr = new GlideRecord('u_choice_1');
        Gr.addQuery('u_type', source.u_type);
        Gr.query();
        if (!Gr.next()) {
			typeFlag = false;
            //ignore = true;
            log.error('type ' + ' ' + type1 + ' ' + 'is not found ');
        }
    }

	if(!approverFlag && !typeFlag){
		ignore = true;
		log.error('Both Approver and Type weren not found');
	}


})(source, map, log, target);


Please mark this as helpful if it resolves your issue. 
Also, if it doesn't, please elaborate the condition that you're trying to validate and we can discuss.