Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

Prevent form save

$
0
0

I'm trying to achieve certain type of logic onSave event via js as follows:

If form lookup equals "Encounter", check that fields contain values, if not alert the user and disable the form from saving. 

I'm getting an error "getEventArgs' of undefined at onSave" on my last function.

I can get my onSave function run by itself when I pass execution context as first parameter in handler properties section.

function workOrderTypeOnSave(){
	getLookup("msdyn_workordertype");
}

function getLookup(lookupSchemaName) {
	var lookupObj = Xrm.Page.getAttribute(lookupSchemaName);
	if (lookupObj != null) {
		var lookupObjValue = lookupObj.getValue();
		if (lookupObjValue != null) {
			var lookupEntityType = lookupObjValue[0].entityType,
			lookupRecordGuid = lookupObjValue[0].id,
			lookupRecordName = lookupObjValue[0].name;
			if (lookupRecordName = "Encounter") {
				onSave();
			}
		}
	}
}

function onSave(context) {
	var saveEvent = context.getEventArgs();
	if (Xrm.Page.getAttribute("msdyn_serviceaccount").getValue() == null || Xrm.Page.getAttribute("cog_dateofbirth").getValue() == null) {
		Xrm.Utility.alertDialog("Please fill all the required fields.");
		saveEvent.preventDefault();
	}
}


 


Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>