Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Pages - Customize & Extend
Unanswered

Make look up fields read only on conditional basis

(0) ShareShare
ReportReport
Posted on by 184

Hi

I have a requirement in portal where when a parent lookup is blank, the child lookup should be read-only. 

I have used the code from the below blog from Oliver but it doesn't work for me.

https://oliverrodrigues365.com/category/power-apps-portals/page/2/

Could anyone advise me please?

 

Thanks

Arj

 

cc: @OliverRodrigues @ragavanrajan @OOlashyn 

Categories:
  • Inogic Profile Picture
    1,023 Super User 2025 Season 1 on at
    Re: Make look up fields read only on conditional basis

    Hi @arjunmusuvathy ,

    In this Scenario we are assuming Contact as parent Lookup and jobs are the child lookup in Dynamics 365 CRM,

    Hence below steps are accordingly contact as Parent and Job as Child.

    The codes will read the Contact on load and on change and work respectively.


    Please follow the steps given below,

    1. Navigate to the in-Portal Management app look for Basic Form and choose the right form where you wish to achieve the functionality,

    2. Click on ‘Additional Setting’ Tab,

    3. Look for the Custom Script JavaScript,

    Inogic_0-1693808284259.png


    Please update the code with parent and child and Paste it in custom JavaScript,


    $(document).ready(() => {

        $("form").ready(() => {

            //On the load if the parentLookup has value then enabling the editing in the child lookup or else disable

            lookupValue = $("#gh_candidate_name").val() == '' || $("#gh_candidate_name").val() == undefined || $("#gh_candidate_name").val() == null ? null : $("#gh_candidate_name").val();

     

            lookupValue == null ? disableChild() : enableChild();

            //onchange of parent Lookup: Lookup has three inputs, copy the id where id is stored of the record

         

    Inogic_1-1693808353737.png

     

            $("#gh_candidate").change(() => {

                lookupValue = $("#gh_candidate_name").val() == '' || $("#gh_candidate_name").val() == undefined || $("#gh_candidate_name").val() == null ? null : $("#gh_candidate_name").val();

                lookupValue == null ? disableChild() : enableChild();

            })

        })

        //functions to show hide

        function disableChild() {

           $("#gh_job").parent().parent().find(".btn.btn-default.launchentitylookup").attr("disabled", "disabled");

            $("#gh_job").parent().parent().find("input").attr("disabled", "disabled");

        }

        function enableChild() {

            $("#gh_job").parent().parent().find(".btn.btn-default.launchentitylookup").removeAttr("disabled");

            $("#gh_job").parent().parent().find("input").removeAttr("disabled");

        }

    })

    Thanks!

     

    Inogic Professional Services Division

    Power Platform and Microsoft Dynamics 365 CRM Development – All under one roof!

    Drop an email at crm@inogic.com

    Services:  http://www.inogic.com/services/

    Power Platform/Dynamics 365 CRM Tips and Tricks:  http://www.inogic.com/blog/

  • arjunmusuvathy Profile Picture
    184 on at
    Re: Make look up fields read only on conditional basis

    Update:

     

    Removing the line of code below fixed the width issue. 

    $('#' + new_childlookup_name).siblings("div.input-group-btn").hide();

     

    Thanks @Fubar @ragavanrajan @saudali_25  for your time.

     

     

    Regards

    Arjun

  • ragavanrajan Profile Picture
    7,036 Most Valuable Professional on at
    Re: Make look up fields read only on conditional basis

    Hi @arjunmusuvathy 

     

    You can increase the size of the child lookup via JavaScript run time - add class and increase the width 

    or add a custom CSS and add the following code 

     

    input#yourchild_lookuplogicalname {
    width: 300px !important;
    }

     

    Save the CSS 

     

    In design studio.> Hit Sync 

     

     

    Hope it helps.
    ------------

    If you like this post, give it a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users to find it.

     

     

  • arjunmusuvathy Profile Picture
    184 on at
    Re: Make look up fields read only on conditional basis

    @Fubar  Thanks for your reply I have used Oliver's code to pass the field name and readonly value and it works like below. It does make the field read only however the fields length is shortened to half. Is this the expected behaviour?

     

    arjunmusuvathy_0-1693385080510.png

     

     

    Thanks

    Arj

  • Fubar Profile Picture
    7,960 Super User 2025 Season 1 on at
    Re: Make look up fields read only on conditional basis

    In Olivers example code he is passing the logical schema name of the field into his function but you are not, so you need to either use his code block and just pass it the logical schema name of the field or change your code as below

    var country = $("new_parentlookupid_name").val();
    
    //Should be
    var country = $("#new_parentlookupid_name").val();
    
    //multiple lines with entries like
    $('#' + new_childlookup_name)
    
    //should be 
    $('#new_childlookup_name')
    
    //where the new_childlookup part is the logical schema name of the Lookup field in question
  • arjunmusuvathy Profile Picture
    184 on at
    Re: Make look up fields read only on conditional basis

    @saudali_25  Please see the code snippet below.

     

    $(document).ready(function ()
    {  
        setChildLookupReadOnly();
     
        $("#new_parentlookupid").on("change", function ()
        {
            setChildLookupReadOnly();
         });
     
         function setChildLookupReadOnly()
         {
              var country = $("new_parentlookupid_name").val();
              if (country == "")
              {
                   $('#' + new_childlookup_name).siblings("div.input-group-btn").find("button").prop("disabled", true);
                   $('#' + new_childlookup_name).siblings("div.input-group-btn").hide();
              }
              else
              {
                   $('#' + new_childlookup_name).siblings("div.input-group-btn").find("button").prop("disabled", false);
                   $('#' + new_childlookup_name).siblings("div.input-group-btn").show();
               }    
            }
    });
  • Saud Ali Profile Picture
    812 Super User 2024 Season 1 on at
    Re: Make look up fields read only on conditional basis

    Hi @arjunmusuvathy ,

     

    Can you share your code snippet that you're using? It would be easier to guide you after looking to the snippet you're using. 

     

    As per the blog you shared, it should work for you.

     

    Thanks,

    Saud

     

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

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

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Featured topics