Prompt for unsaved record

This question is not answered

Hi - does anyone know of how I can add a prompt in Sage CRM 7.3 2018 to save a record if it has been modified and not saved when a user tries to goes to another screen?

Many thanks for any help!

All Replies
  • I have done this in the past. May require some tweaking depending on the theme and version.  If a user clicks anywhere except for Save or Cancel, they will get an alert that says they need to click Save or Cancel.

    The below script I added to custom content on the company summary, the first thing is to check if in edit mode, so I check that on comp_name field.. It does not prevent navigating via back or forward browser buttons.

    $(document).ready(function(){

    var strMode = crm.fields("comp_name").getMode();

    if (strMode=="edit"){

    $("td").each(function(e){

    this.onclick="return false;";

    });

    $("img").each(function(e){

    this.onclick="return false;";

    });

    $("img").on("contextmenu",function(e){

    return false;

    });

    $("span").each(function(e){

    this.onclick="return false;";

    });

    $("span").on("contextmenu",function(e){

    return false;

    });

    $("html").click(function (e)

    {

    id=$(e.target).attr("id");

    //'if(id=="Button_Save"){

    //' alert(id);

    //'}

    myid=$(e.target).closest("form").attr('name');

    if(myid != "EntryForm" && id !="Button_Save" && id !="Button_Cancel")

    {

    alert("Please Click Save or Cancel to Exit Screen");

    e.preventDefault();

    }else

    {}

    });

    }

    });

  • Thank you matarazzo81 really appreciate your reply!  I shall give it a go :-)

  • Hi matarazz081 I have tried this and it doesn't seem to work in CRM 7.3.  I will have a play around with it but so far unable to figure out why its not working. Sadly the code doesn't seem to have any effect at all on the screen.

  • What screen are you putting it into the custom content for?

  • Hi - in the company detail screen (but want to also use it in person and opportunity screens!)

  • I have tweaked and tested, successfully, the below script on 7.3c sage and contemporary themes.  Place the script in the custom content of companyboxlong for company.  For person place it in PersonBoxLong custom content and change the 3rd line to pers_firstname instead of comp_name.  

    <script>

    $(document).ready(function(){

    var strMode = crm.fields("comp_name").getMode();

    if (strMode=="edit"){

    $("td").each(function(e){

    this.onclick="return false;";

    });

    $("img").each(function(e){

    this.onclick="return false;";

    });

    $("img").on("contextmenu",function(e){

    return false;

    });

    $("span").each(function(e){

    this.onclick="return false;";

    });

    $("span").on("contextmenu",function(e){

    return false;

    });

    $("html").click(function (e)

    {

    id=$(e.target).attr("id");

    sourcevalue=$(e.target).attr("src");

    if(sourcevalue){

    if (sourcevalue.indexOf("Save.gif") >= 0 || sourcevalue.indexOf("Cancel.gif") >= 0){

    id="SaveCancel";

    }

    }

    //'if(id=="Button_Save"){

    //' alert(id);

    //'}

    myid=$(e.target).closest("form").attr('name');

    if(myid != "EntryForm" && id !="Button_Save" && id !="Button_Cancel" && id !="SaveCancel")

    {

    alert("Please Click Save or Cancel to Exit Screen");

    e.preventDefault();

    }else

    {}

    });

    javascript:void(0);

    }

    });

    </script>

  • Argh that worked thank you so much!  It does help if your on the right screen doesn't it :-)

    Your a star thank you!