How to Validate inbound data through Import set API before creating incident

String
Kilo Sage

Hi all,

we created web-service through import set API ,but while giving the wrong data values like Impact:ABC and urgency:XYZ in json as show below ,Still the data is inserting .

Please help me to validate data before inserting record 

{

"u_description":"test",
"u_short_description":"test",

"u_urgency":"XYZ", //instead 1-High
"u_impact":"ABC", ////instead 1-High

}

1 ACCEPTED SOLUTION

Hi Kiran,

So you can handle this using onBefore transform script for that import set web service

sample script below

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

	// Add your code here

	var urgencyArray = ['1-High','2 - Medium','3 - Low'];
	var impactArray = ['1-High','2 - Medium','3 - Low'];
	
	var arrayUtil = new global.ArrayUtil();

	var incomingUrgencyValue = source.u_urgency;
	var incomingImpactValue = source.u_impact;

	if(!arrayUtil.contains(urgencyArray,incomingUrgencyValue)){
		ignore = true;
		status_message= 'Urgency value is not valid';
	}

	if(!arrayUtil.contains(impactArray,incomingImpactValue)){
		ignore = true;
		status_message= 'Impact value is not valid';
	}

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

Regards
Ankur

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

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Kiran,

Are you saying you want to validate if the values are valid during the import set load?

if yes then you will have to write onBefore transform script

please explain in details what and how the setup is currently?

Regards
Ankur

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

In my current setup, created web-service through import set API and created source table  and map the fields  with Mapping Assist(source fields are mapped to target fields),So when we receive the Json ,Import set API will automatically map and create incident ticket .

So now we want to validate the Json data and values are valid or not ,before moving to import set 

Hi Kiran,

So you can handle this using onBefore transform script for that import set web service

sample script below

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

	// Add your code here

	var urgencyArray = ['1-High','2 - Medium','3 - Low'];
	var impactArray = ['1-High','2 - Medium','3 - Low'];
	
	var arrayUtil = new global.ArrayUtil();

	var incomingUrgencyValue = source.u_urgency;
	var incomingImpactValue = source.u_impact;

	if(!arrayUtil.contains(urgencyArray,incomingUrgencyValue)){
		ignore = true;
		status_message= 'Urgency value is not valid';
	}

	if(!arrayUtil.contains(impactArray,incomingImpactValue)){
		ignore = true;
		status_message= 'Impact value is not valid';
	}

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

Regards
Ankur

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

thanks you soo much this is what we are looking for ,but we have 100 of values to validate like group value contains 100 values we cant hard code values her ,So any dynamic way to validate ?