Hi, I'm running the code below on the save of a quick create form (and passing in context). When there are no errors it runs and saves fine. When an error is encountered it prevents the save as it should and displays error messages in the validateXX functions. The problem is once I clear up the errors the save button will not function. The mouseover works, but it does not respond to the click. What I did notice is the little blue dots at the top of the quick create continue to cycle like the page is loading. Thoughts or hints?
function form_OnSave()
{
var errorCount = 0;
var activityType = Xrm.Page.getAttribute("ocsd_k9activitytype").getValue();
if (activityType == null)
{
alert("Something went wrong, there is not activity type for this record, please contact Systems");
arguments[0].getEventArgs().preventDefault();
}
if (activityType == 868030004) //training scenario validation
{
errorCount = validateScenario() + validateMeasurement() + validateTraining() + validatePassFail() + validateAmountQty();
}
else
{
errorCount = validateAmountQty() + validateField() + validateMeasurement();
}
if (errorCount != 0) {
arguments[0].getEventArgs().preventDefault();
}
}
*This post is locked for comments
This is what is working for me...
onSaveHandler = function (context) {
var saveButton = null;
var getAttribute = function() {
var attribute = saveButton.getAttribute("disabled");
// Check that the attribute is ready
if (attribute == null) {
setTimeout(getAttribute, 2000);
return;
}
saveButton.removeAttribute("disabled");
};
var enableSaveButton = function () {
var buttonName = "globalquickcreate_save_button_NavBarGloablQuickCreate";
saveButton = parent.document.getElementById(buttonName);
if (!saveButton) {
saveButton = top.document.getElementById(buttonName);
}
// Check that the element is ready
if (saveButton == null) {
setTimeout(enableSaveButton, 1000);
return;
}
getAttribute();
};
if (!isAddressValidated) {
context.getEventArgs().preventDefault();
// Enable save button
enableSaveButton();
addressValidation().done(function(result) {
if (result) {
isAddressValidated = true;
Xrm.Page.data.entity.save("saveandclose");
}
});
}
}
Thank you Hicham for your answer. I've tried this code but I had 2 issues with that:
- The Quick Create form is in an iFrame, so you have to go to the parent node to get the button element.
- You cannot get an element by a simple getElementById or something else equivalent in jQuery as long as it is not supported. This returns null at each time.
I've tried then this code which was inspired from yours and it does work fine for me. You just have to call enableSaveButton() function just after PreventDefault.
var saveButton = null;
function enableSaveButton() {
saveButton = parent.document.getElementById('globalquickcreate_save_button_NavBarGloablQuickCreate');
// Check that the element is ready
if (saveButton == null) {
setTimeout('enableSaveButton()', 2000);
return;
}
getAttribute();
}
function getAttribute() {
var attribute = saveButton.getAttribute("disabled");
// Check that the attribute is ready
if (attribute == null) {
setTimeout('getAttribute()', 2000);
return;
}
saveButton.removeAttribute("disabled")
}
you can renable the button with this like of code just after PreventDefault:
$('#globalquickcreate_save_button_NavBarGloablQuickCreate').prop('disabled',false);
Hi there,
We are April 5 2017, working with Dynamics CRM 365 and I can see that this issue is still alive :
Using this method with a quick form, save button is disable and the form need to be posted with Crtrl+S !
Actually, I can see that there is no hurry for Microsoft to address this issue !
Does anyone experimented a solution or workaround for this issue ?
Thanks for the feedback,
Emmanuel Barache
CRM Consultant
NOVULYS
Hello,
I have the same problem CRM 2016 on-prem and SP1. The save button remains disabled.
But you can still save the form with Ctrl+S.
Ref: https://community.dynamics.com/crm/f/117/t/191954
Hi casualties ;)
I have the same issue. The Save button stops working after preventDefault() call (but Crtl + S continue working). I think it's a bug from Microsoft.
Did you find a solution, or any workaround?
Regatds,
FV
I'm experiencing the same issue. Progress "balls" are moving and I'm not able to trigger the save event again by clicking the save button. Never seen this issue on normal forms before.
Looking at the HTML of the save button i can see that the preventDefault() function actually added an disabled="disabled" attribute to the save button html. So most likely a bug.
Hi Srini,
After execute of context.getEventArgs().preventDefault(), i am not able to save the record again from quick create form
Nausher
Hi David,
I am suspecting about initialization of arguments[0] .
for onsave method executioncontext is automatically passed.
here arguments[0] should be executioncontext.
Hope this helps!!
Srini Ch
Mark As Answer ,if you get answer of your question :)
I am gettng the same issue.
I believe i have the same issue occurring. I also notice after the preventdefault the blue dots at the top of the form usually indicating that the form is loading.
I believe this is microsofot bug.
what is arguments[0] ?
Please refer the below link for using preventdefault in correct way :
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156