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

@kiranchand 

I believe you will have to do it for every incoming value separately.

Please check this question also. I believe this is answered. Please mark appropriate response as correct and helpful.

how to insert attachment(inbound) for incident using attachment API

Regards
Ankur

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

Hi @Ankur Bawiskar ,

We have to  do separately means  lot of hardcodes values we have to keep like assignment group values are 80 are there ,Any dynamic way to validate ?

Hi Kiran,

you can use system property to hold the values you want to validate against

Example:

property will hold comma separated 80 values of group names

then you can validate as below

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

	// Add your code here

	var groupValues = gs.getProperty('group_names').toString();
	
	var incomingGroupName = source.u_group_name;
	
	var arr = groupValues.split(',');
	
	var arrayUtil = new global.ArrayUtil();

	if(!arrayUtil.contains(arr,incomingGroupName)){
		ignore = true;
		status_message= 'Group name is not valid';
	}

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

Regards
Ankur

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