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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

OnSave confirmation Dialog box and Readonly form

(0) ShareShare
ReportReport
Posted on by 280

Hi, I have this plugin which triggers on update of specific status reason. Instead of triggering directly when saved, I used an OnSave Jscript for a confirmation dialog. The process needs to be saved only when Call back is YES, if it is yes then I want another alert box to show the process is successful. After the record is saved I want it to be Read-only( still record would be active) , even when the record is accessed later. Here is the Jscript I have been using OnSave. 

function confirmOpp(context) {

    if (Xrm.Page.getAttribute("statuscode").getValue() == 100000000) {
        Xrm.Utility.confirmDialog("Click OK to run the process or Cancel to go back. Ok ?", function () {

            alert("Operation Successful");

            
            Xrm.Page.data.entity.attributes.forEach(
    function (attribute, index) {
        if (Xrm.Page.getControl(attribute.getName()) != null) {
            Xrm.Page.getControl(attribute.getName()).setDisabled(true);
        }
       
    });

        }, function () {
            var saveEvent = context.getEventArgs();
            saveEvent.preventDefault();
        });
    }
    
}


I wrote the above code, It executes successfully the first time. Once the for becomes read only, and when tried to refresh or go back. the Confirm dialog pops up again saving the form again. Also, when I go back and check the record, it is not read-only anymore. Please help me if I have to change anything in my script. And I only want to achieve it using JScript. Thanks in advance.

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    You need to Setdisable all attributes also on the Onload of the form using JS  if you want to achieve it when you refresh the page or go back .

    A possible solution could be to create a new flag and when you save the record you also set a value on this flag , then you check this flag on the onload function if it has the value you setdisable all attributes of the form

  • Suggested answer
    Community Member Profile Picture
    on at

    You will definitely need a field to know whether you should lock the form. Otherwise system will not know whether to lock the form during the on load.

    What you can do is to create a simple function to lock the form and call it during the on load and on save event.

    function OnLoad()

    {

     lockform();

    }

    function OnSave()

    {

     if (confirm)

     {

       set locked = true;

       lockform();

     }

     else

     {

       prevent save

     }

    }

    function lockform()

    {

     if (locked)

       disable all fields

    }

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans