locked
Business Required and Read-Only field doesn't ask for provide a value. RRS feed

  • Question

  • Hi all,

    I have a Business Required Read-only field, that's like this because it gets his value from an event depending on the values of a two Options set and I don't want user to modify it manually.

    The problem is that I can save the entity without fill this field.

    I already have tried in my javascript this:

    Xrm.Page.getAttribute("fieldName").setSubmitMode("always");

    But it still allows me save the entity without fill in the field.

    Any sugestions?

    Thanks a lot!


    Js

    Thursday, July 19, 2012 4:08 PM

Answers

  • Hello,

    Ok try following:

    During the registration of OnSave event handle check checkbox Pass Execution context as a first parameter and modify your function to following:

    function OnSaveHandler(ExecutionObj)
    {
    	if (Xrm.Page.getAttribute("fieldName").getValue() == null)
    	{
    		alert('Not all required fields are filled. Correct it before saving!');
    		ExecutionObj.getEventArgs().preventDefault();
    	}
    }


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

    • Marked as answer by Gresziu_Dub Friday, July 20, 2012 8:59 AM
    Friday, July 20, 2012 8:48 AM
    Moderator

All replies

  • Hello,

    Try to add following code to OnSave handler:

    if (Xrm.Page.getAttribute("fieldName").getValue() == null)
    {
    alert('Not all required fields are filled. Correct it before saving!');
    Xrm.Page.context.preventDefault();
    }
    This code will be triggered once user will click save or save and close and would not allow to save record till your disabled field would contain value.


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter


    Thursday, July 19, 2012 4:15 PM
    Moderator
  • Hi Andrii,

    thanks for the response!

    I think yours is better way to solve that, I already have tried and I get the error Object doesn't support property or method prevent Default.

    I also have tried with 

    Xrm.Page.context.getEventArgs().preventDefault();

    but I get the same error, and without this line it allows me to save.


    Js


    Friday, July 20, 2012 8:34 AM
  • Hello,

    Ok try following:

    During the registration of OnSave event handle check checkbox Pass Execution context as a first parameter and modify your function to following:

    function OnSaveHandler(ExecutionObj)
    {
    	if (Xrm.Page.getAttribute("fieldName").getValue() == null)
    	{
    		alert('Not all required fields are filled. Correct it before saving!');
    		ExecutionObj.getEventArgs().preventDefault();
    	}
    }


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

    • Marked as answer by Gresziu_Dub Friday, July 20, 2012 8:59 AM
    Friday, July 20, 2012 8:48 AM
    Moderator
  • Good!! Thanks!!

    Js

    Friday, July 20, 2012 9:00 AM