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

I have the same question (0)
  • Suggested answer
    WhosComingforSupport Profile Picture
    40 on at

    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)

    });

    }

  • Sakib Profile Picture
    90 on at

    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
    sardar ahmed Profile Picture
    520 on at

    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

  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    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.

  • Sakib Profile Picture
    90 on at

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

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    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.

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans