web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Error Javascript GetSaveMode

(0) ShareShare
ReportReport
Posted on by 694

Dears, good morning,

I'm running the code below, but the getSaveMode event isn't working anymore, would you know why?

function End (executionContext)
{
debugger;

try
{
var formContext = executionContext.getFormContext ();

var currentUserRoles = Xrm.Utility.getGlobalContext (). userSettings.securityRoles;

for (var i = 0; i <currentUserRoles.length; i ++)
{
Xrm.WebApi.online.retrieveMultipleRecords ("role", "? $ Select = name & $ filter = roleid eq" + currentUserRoles [i] + ""). Then
(
function success (results)
{
var AccessAccess = results.entities [0] ["name"];

if (RightAccess! = "XXX")
{
var eventArgs = executionContext.getEventArgs ();

if (eventArgs.getSaveMode () == 58)
{
eventArgs.preventDefault ();
}
}
},
function (error) {
Xrm.Utility.alertDialog (error.message);
}
);
}
}
catch (e)
{
alert ("Error in END function:" + e.message);
}
}

Thank you

I have the same question (0)
  • Suggested answer
    Rodrigo Hentz Profile Picture
    on at
    RE: Error Javascript GetSaveMode

    Hi Ricardo Rodrigues, how are you?

    Ricardo, try to use executionContext.getEventArgs().getSaveMode() like documented at https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/save-event-arguments/getsavemode 

    In this way you will able to get the save mode.

    Please let me know if this information helped on your question. 

    Regards.

    Rodrigo Hentz

    Microsoft Support Engineer

  • Ricardo Rodrigues dos Santos Profile Picture
    694 on at
    RE: Error Javascript GetSaveMode

    Rodrigo good afternoon,

    Thank you for your help.

    I added the code below, but I couldn't stop canceling the Mark as Done button event.

    function End(executionContext)

    {

    debugger;

    try

       {

       var formContext = executionContext.getFormContext ();

           var currentUserRoles = Xrm.Utility.getGlobalContext (). userSettings.securityRoles;

    for (var i = 0; i <currentUserRoles.length; i ++)

    {

    Xrm.WebApi.online.retrieveMultipleRecords ("role", "? $ Select = name & $ filter = roleid eq" + currentUserRoles [i] + ""). Then

    (

    function success (results)

    {

    var AccessAccess = results.entities [0] ["name"];

    if (RightAccess! = "XXX")

    {

    var eventArgs = executionContext.getEventArgs ();

    if (eventArgs.getSaveMode () == 58)

    {

    executionContext.getEventArgs (). getSaveMode ();

    //eventArgs.preventDefault ();

    }

    }

    },

    function (error) {

    Xrm.Utility.alertDialog (error.message);

    }

    );

    }

    }

    catch (e)

    {

    alert ("Error in the Endfunction:" + e.message);

    }

    }

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at
    RE: Error Javascript GetSaveMode

    Hi,

    You should add below code

    if (eventArgs.getSaveMode () == 58)

    {

    executionContext.getEventArgs().preventDefault();

    }

    Please mark my answer verified if i were helpful

  • Ricardo Rodrigues dos Santos Profile Picture
    694 on at
    RE: Error Javascript GetSaveMode

    Hello Bipin,

    Thank you for your help.

    I inserted the code below, it is still allowing to save, I inserted something wrong in the code

    if (eventArgs.getSaveMode () == 58)

    {

    executeContext.getEventArgs (). preventDefault ();

    }

  • Suggested answer
    Rodrigo Hentz Profile Picture
    on at
    RE: Error Javascript GetSaveMode

    Hi Ricardo, how are you?

    You can use the same variable name for the context.

    At the form, at onSave, do not forget to pass the context to the function.

    Final script could be:

    function myFormOnSave(executionContext)

    {

          if (executionContext.getEventArgs().getSaveMode() == 58)

          {

              executionContext.getEventArgs().preventDefault();

        }

    }

    Articles - https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/save-event-arguments/getsavemode and docs.microsoft.com/.../preventdefault

    Please let me know if this information helped on your question.

     

    Regards.

    Rodrigo Hentz

    Microsoft Support Engineer

  • Ricardo Rodrigues dos Santos Profile Picture
    694 on at
    RE: Error Javascript GetSaveMode

    Rodrigo good morning,

    Thanks for the reply, I made the change in the code, but even so it is allowing the registration to be completed and the action of the button is not

    Tanks

  • Suggested answer
    Rodrigo Hentz Profile Picture
    on at
    RE: Error Javascript GetSaveMode

    Hi Ricardo, thanks for the update.

    In this case my advise is to create a support ticket with us.

    That way a more deep investigation can be done.

    Regards.

    Rodrigo Hentz

    Microsoft Support Engineer

  • Swethagampala Profile Picture
    10 on at
    RE: Error Javascript GetSaveMode

    Anyone found solution to this issue? I am also having same issue. getSaveMode() is no longer available 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 235

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 177

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 156 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans