Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Error Javascript GetSaveMode

Posted on by 690

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

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

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

  • Suggested answer
    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

  • 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
    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

  • 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
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 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

  • 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
    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans