Hello,
I am trying to perform a test on presence of unsaved text in a text field before the user "Save & Close" their case. "Save & Close" is performed via button, with OOB function:
Library: $webresource:Main_system_library.js
Function Name: XrmCore.Commands.Save.saveAndCloseForm
Crm Parameter =PrimaryControl
I have decided to use XrmToolBox Ribbon Workbench to assign my own function to the "Save & Close" button, form my own .js library, which will:
- Test if there is an unsaved text
- If there is -> Gives alert and does nothing
- If there is not -> Performs the same action as XrmCore.Commands.Save.saveAndCloseForm
Of course, $webresource:Main_system_library.js is not freely accessible since it is OOB Microsoft script. Now here is what I attempted, and where the problem is (if test works as intended):
if (textInPortalComment) {
console.log("There is text in the Portal Comment field in Action Log.");
Xrm.Utility.alertDialog("You have unsaved text in the Portal Comment field!");
} else {
console.log("There is NO text in the Portal Comment field in Action Log.");
/*
HERE IS THE PROBLEM - DO NOT KNOW HOW TO EXECUTE THE FUNCTION THAT XrmCore.Commands.Save.saveAndCloseForm DOES:
saveAndCloseForm(); - DOES NOTHING (expected)
formContext.data.entity.save("saveandclose"); - DOES NOTHING
Mscrm.SaveAndClosePrimary(); - DOES NOTHING (expected)
Xrm.Page.data.save("saveandclose"); - GIVES ERROR: 0x83215603
*/
Xrm.Page.data.entity.save("saveandclose"); // - GIVES ERROR: 0x83215603
};
Of course, what would be ideal, if I could in my own Custom JavaScript Action directly call the function XrmCore.Commands.Save.saveAndCloseForm form $webresource:Main_system_library.js. Or if I could at least access the $webresource:Main_system_library.js so I could copy XrmCore.Commands.Save.saveAndCloseForm into my own code, or some similar solution.
Any insight on how to call, or at least copy a function from Main_system_library.js (specifically function XrmCore.Commands.Save.saveAndCloseForm) in my own .js script?