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

Prevent saving crm record using preventDefault is nor working

$
0
0

I want to cancel saving process if the new_name is existing in the current entity.
Here's what i have tried:

function preventsave(context){
	var login_name = Xrm.Page.getAttribute("new_name").getValue();
	var Entity = "new_parentrecord";
	var Select = "?$select=new_name";
	var Filter = "&$filter=new_name eq '"+ login_name +"'";
	var saveEvent = context.getEventArgs();
//alert(login_name);
	Xrm.WebApi.retrieveMultipleRecords(Entity, Select + Filter).then(
		function success(result) {
			alert("Login Name Exist !!");
			if (result.entities[0].new_name !== null) {
				SetPageNotification("Login Name Exist !", "INFO", "InfoNotification");
				saveEvent.preventDefault(); //1st prevent
			}
		},
		function (error) {
			console.log(error.message);
		}
	);
	saveEvent.preventDefault(); //2nd prevent
}

function SetPageNotification(aMessage, aType, aNotificationName) {

       Xrm.Page.ui.setFormNotification(
         aMessage,
         aType,
         aNotificationName
       );
   }

function ClearAllNotifications() {
       ClearPageNotification("InfoNotification");
}

after trial and error i noticed that the 1st prevent is not working. but the 2nd prevent is working. Can you help me to make the 1st prevent to work ?


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images