how to validate empty data in transform map?

jobin1
Tera Expert

Hi All,

 

I need to validate below excel data while doing transform load (before loading to table)

Validation should be like if the bae64 data is empty then it should not allow to load data.

find_real_file.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@jobin 

you can use onbefore transform script

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

	// Add your code here
	if(source.u_base64_data.nil())
		ignore = true;

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

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

20 REPLIES 20

jobin1
Tera Expert

@Ankur Bawiskar  Any idea?

Anshu_Anand_
Kilo Sage
Kilo Sage

In transform map before script, you can use

if(source.bae64_data === "")

{

ignore=true; // ignore entire row

}

Regards,
Anshu

Ankur Bawiskar
Tera Patron
Tera Patron

@jobin 

you can use onbefore transform script

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

	// Add your code here
	if(source.u_base64_data.nil())
		ignore = true;

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

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

jobin1
Tera Expert

@Ankur Bawiskar Also I need to show an error message in error reason column of staging table. I tried with below code its not working. Please help.

On before transform script

 

var cat_num = source.u_number;
var cat_item = source.u_item;
var fname = source.u_filename;
Var ritmstate = source.u_state;
var contenttype = source.u_content_type;
var bae64 = source.u_base64_data;


//Source table map - ends here...

var category1,sub_category1,subcategory22,user_id,username,country,company,phone,assignment_group,company_sysid,asigntosysid,stateid,openstateid,rescatgsysid,clscode,urgcyvalue;
var errornote = " ";

//State validation starts......

if (ritmstate != '' && ritmstate != null && ritmstate != undefined) {
var stateval = new GlideRecord('sys_choice');
stateval.addQuery('name', 'sc_req_item');
stateval.addQuery('element', 'state');
stateval.addQuery('label', ritmstate);
stateval.query();
if (stateval.next()) {
stateid = stateval.value;
} else {

stateid = '';
}
}
//State validation ends........


//Error message update in staging table starts
else
{
source.u_error_state = true;

var invaliderror = "";
var mandatoryerror = "";
var invalidmessage = "";
var statemessage = "";
var mandmessage = "";



if(ritmstate == 'Closed Complete' || ritmstate == 'Closed Incomplete' || ritmstate == 'Closed Skipped' || ritmstate == 'Cancelled')
{
statemessage = "RITM cannot be created in " + ritmstate +" State.";
}

if(source.bae64_data == "")

{
statemessage = "RITM cannot be created.Missing Bae64data ";
errornote = statemessage;
source.u_error_reason = errornote;
}


if(source.u_filename === "")

{
statemessage = "RITM cannot be created.Missing file name ";
errornote = statemessage;
source.u_error_reason = errornote;
}
if(source.u_content_type == "")

{
statemessage = "RITM cannot be created.Missing content type ";
errornote = statemessage;
source.u_error_reason = errornote;
}