Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

How to lock fields conditionally in CRM

(0) ShareShare
ReportReport
Posted on by 90

Hello,

I have a situation where I need approval for all Task and I have used custom Task entity where I have created 25 fields

I want if Approval equals to 'yes' then lock 10 fields in between this 25 field

I know it's possible in Business Rules but I need JavaScript for this

Please response on my requirement ASAP

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,961 Moderator on at
    RE: How to lock fields conditionally in CRM

    Hi,

    You should prefix 'header_process_field schema name'.

    Check below article.

    www.tecman.co.uk/.../259-hiding-multiple-fields-with-javascript-in-business-process-flows

    If found helpful, Please mark my answer verified.

  • Sakib Profile Picture
    Sakib 90 on at
    RE: How to lock fields conditionally in CRM

    One small problem- This code is not working on Form's Header portion Fields

  • Verified answer
    Bipin D365 Profile Picture
    Bipin D365 28,961 Moderator on at
    RE: How to lock fields conditionally in CRM

    Hi,

    Parameter passed should be as below and add below line of code in your javascript to fix error.

    function disableFormFields(executionContext)

    {

    var formContext= executionContext.getFormContext();

    aprv =formContext.getAttribute("new_approval").getValue();

    if(aprv == true){

    disable_fields = ["new_assign","subject"]

    disable_fields.forEach(x => {

    formContext.getControl(x).setDisabled(true)

    });

    }

    }

    docs.microsoft.com/.../getformcontext

    If found helpful, Please mark my answer verified.

  • Suggested answer
    sardar ahmed Profile Picture
    sardar ahmed 520 on at
    RE: How to lock fields conditionally in CRM

    Hi Sakib,

    You need to pass formcontext to above function as below

    function disableFormFields(formContext) {
    //Your code
    }

    and make sure, you are passing execution context as first parameter in the function call.

    pastedimage1596012555210v1.png

  • Sakib Profile Picture
    Sakib 90 on at
    RE: How to lock fields conditionally in CRM

    Hi,

    I have used above mentioned code in my form's Approval Field On change

    After choosing Approval equals to yes then showing below Script Error

    1856.WhatsApp-Image-2020_2D00_07_2D00_29-at-12.20.26-PM.jpeg

    And I have represent this code on this way-

    function disableFormFields()
    {

     aprv =formContext.getAttribute("new_approval").getValue();

    if(aprv == true){

     disable_fields = ["new_assign","subject"]

    disable_fields.forEach(x => {

    formContext.getControl(x).setDisabled(true)

    });

    }

    }

  • Suggested answer
    RE: How to lock fields conditionally in CRM

    Hi Sakib

    If you want the user to not be able to access the fields, rather than locking them you could just set them to be invisible. You can do this with both Business Rules and JavaScript.

    Another answer here gives a good idea of how to do this with JavaScript with the setDisabled() function.

    A possible solution looks SOMETHING like this; note that I haven't tested it:

    aprv = formContext.getAttribute("approval").getValue();

    if(aprv == true){

    disable_fields = ["field1","field2",....]

    disable_fields.forEach(x => {

    formContext.getControl(x).setDisabled(true)

    });

    }

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans