The CreatorCon Call for Content is officially open! Get started here.

Help with Transform script returning Undefined

mdjoseph12
Giga Contributor

Im calculating whether the dates coming within the imports are today or later and based upon that value it'll  determine what to set the field map too, but I am continuing to receive undefined: 

 

answer = (function transformEntry(source) {
	
	var today = new GlideDate();
	var stage;
	var year = today.addYears(1);
	if (source.u_date_type =="Construction Start") {
		var date = source.u_actual_start_date;
		if (date >= today) {
			stage = "Under Construction";
		}
	} else if (source.u_date_type =="Reopen Date") {
		var dates = source.u_actual_start_date;
		if (dates >= today) {
			stage = "Re-opened";
		} else if (dates >= year) {
			stage = "Complete";
		}
	}
	return stage; // return the value to be put into the target field
	
})(source);
1 ACCEPTED SOLUTION

dvp
Mega Sage

Try this 

answer = (function transformEntry(source) {
	
	var stage;
	var today = new GlideDateTime();
	
	var year = new GlideDateTime();
	year.addYears(1);
	
	var actual = new GlideDateTime(source.u_actual_start_date);
	
	var diff = gs.dateDiff(today, actual, true);

	if (source.u_date_type =="Construction Start") {
		
		if (diff >= 0) {
			stage = "Under Construction";
		}
	} else if (source.u_date_type =="Reopen Date") {
		
		//Update the below logic as the above one
		var dates = source.u_actual_start_date
		if (dates >= today) {
			stage = "Re-opened";
		} else if (dates >= year) {
			stage = "Complete";
		}
	}
	return stage; // return the value to be put into the target field
	
})(source);

View solution in original post

6 REPLIES 6

Prateek kumar
Mega Sage

Try?

answer = (function transformEntry(source) {
	
	var today = new GlideDate();
	var stage;
	var year = new GlideDate();
            year.addYears(1);
	if (source.u_date_type =="Construction Start") {
		var date = source.u_actual_start_date;
		if (date >= today) {
			stage = "Under Construction";
		}
	} else if (source.u_date_type =="Reopen Date") {
		var dates = source.u_actual_start_date;
		if (dates >= today) {
			stage = "Re-opened";
		} else if (dates >= year) {
			stage = "Complete";
		}
	}
	return stage; // return the value to be put into the target field
	
})(source);

Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Thanks Prateek, unfortunately the stage is coming in as undefined