web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Can't get to work Javascript web resource to Handle form verifications

(0) ShareShare
ReportReport
Posted on by 10

Hello,

          I have been trying to validate a form Lookup field but it just doesnt seem to work, I have tried many ways in the Javascript and nothing, it just doesn't seem to work, Basically

I need to verify one field on the form of case, if that field has a Determined text another field gets blocked if not the other field is enabled, this seems pretty basic but everytime I try to do it nothing happens, I have even tried with a normal text on an Alertin the browser and it doesn't work either. I'm just starting with Dynamics 365 and I'm not really sure if I'm doing something wrong when loading the JS, The event handler is created in the field itself (the one I need to capture the text ) and is an onChange type, I'm not really sure if I need to add other parameters but so far it hasn't worked.

this is the code of the Script:

function serviceType(executionContext)
{
    debugger;
    var formContext =executionContext.getFormContext();
    var serviceType = formContext.getAttribute("c9_caseservicetype");
     
    if (serviceType != null) {
        
        var text = serviceType[0].name;

       if(text == "TM"){
        formContext.getControl("c9_contract").seDisabled(true);
           
       }
    }
}

As you can see the functionality I'm looking for is quite simple but I can't get it to work, maybe I can accomplish the same with business rules but I just want to learn how to apply scripts for harder modifications that might be not possible with business rules. Any help will be appreciated.

Thanks in advance.

I have the same question (0)
  • Suggested answer
    Vinoth8549 Profile Picture
    5 on at

    Hello Jorge,

    Try this 

     var serviceType = formContext.getAttribute("c9_caseservicetype").getValue();

     Have you checked the context parameter on the form events ? So it will trigger this function 

    Thanks

  • JorgeDiaz Profile Picture
    10 on at
    [quote user="Vinoth8549"]

    Hello Jorge,

    Try this 

     var serviceType = formContext.getAttribute("c9_caseservicetype").getValue();

     Have you checked the context parameter on the form events ? So it will trigger this function 

    Thanks

    [/quote]

    I changed and the same, this is what I have on the lookup event, this is on the lookup field not on the entire form.

    pastedimage1652332956054v1.png

  • Verified answer
    Amit Katariya007 Profile Picture
    10,409 Moderator on at

    Hello Jorge,

    I have checked your code and found that you have not placed any null checks in the given code for lookup.

    Please refer below code where I am checking if lookup field is null or not. If lookup is null/blank then I will make setDisable(false)

    else I will get the lookup value and then check the name of the lookup field.

    if it will match with the respective name then I will make setDisable(true) else I will make as make setDisable(false).

    Also your code is not correct you have used seDisable(false) rather than setDisable(false).

    function serviceType(executionContext)
    {
        debugger;
        var formContext =executionContext.getFormContext();
         
        if (formContext.getAttribute("ownerid").getValue() != null) //Check if lookup is null or not
        {
           var serviceType = formContext.getAttribute("ownerid").getValue()[0].name; //if it is not null then Get Lookup value name
           if(serviceType == "Amit Katariya") // COmpare it with specific name
           {
                formContext.getControl("cr791_cartofirstid").setDisabled(true);      //execute if condition is satisfied  
           }
           else
           {
                formContext.getControl("cr791_cartofirstid").setDisabled(false);     //execute if condition is not satisfied      
           }
        }
        else
        {
            formContext.getControl("cr791_cartofirstid").setDisabled(false);        //execute if lookup is null
        }
    }

    You can see below screenshots for your reference.

    1. pastedimage1652367638670v1.png

    2.pastedimage1652367667746v2.png

    3.pastedimage1652367697131v3.png

    Thank you,

    Amit Katariya

  • Suggested answer
    JorgeDiaz Profile Picture
    10 on at

    That did it Amit, thank you so much for your help, basically I've never used Lookup before so that's why the logic of the code was totally wrong. This is for learning.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 60 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 43

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans