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 :
Microsoft Dynamics CRM (Archived)

How to set of the Job Title, If Job Title is other, enable the field Other job title and set it as mandatory, else disable it on the form (i.e. set it as Read Only)

(0) ShareShare
ReportReport
Posted on by

Hey I have two fields

1)  Job title : Option set that include an option"others"

2) Other Job title : Single Text 

when the user choose others, the "other job title" should be set as mandatory otherwise if he chooses one of the options it should be read only.

I used the following code but it's giving me an error.. Any suggestion?

//if the user chooses from the option other job title
//enable other job title field
//make other job title mandatory
//else if the user chooses one of the options make other job title read only

function EnableOtherJobTitle()

var jobtitle= Xrm.Page.getAttribute("new_jobtitle").getSelectedOption().value;

alert(jobtitle);

if (jobtitle ==100,000,004)
{
Xrm.Page.getAttribute("new_otherjob").setRequiredLevel("required");
}
else
{
Xrm.Page.ui.controls.get("new_otherjob").setDisabled(true);
}
}

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi,

    Please remove the commas in optionset value.

    function EnableOtherJobTitle()
    var jobtitle= Xrm.Page.getAttribute("new_jobtitle").getSelectedOption().value;
    alert(jobtitle);
    if (jobtitle ==100000004)
    {
    Xrm.Page.getAttribute("new_otherjob").setRequiredLevel("required");
    }
    else 
    {
    Xrm.Page.ui.controls.get("new_otherjob").setDisabled(true);
    }
    }

    Hope this helps.

  • Rahul G J Profile Picture
    605 on at

    Hi,

    You try using the below code

    var jobtitle= Xrm.Page.getAttribute("new_jobtitle").getValue();

    alert(jobtitle);

    if (jobtitle ==100000004)

    {

    Xrm.Page.getAttribute("new_otherjob").setRequiredLevel("required");

    }

    else

    {

    Xrm.Page.ui.controls.get("new_otherjob").setDisabled(true);

    }

    }

    Hope this helps, if helps plz mark the answer verified.

    Regards,

    Rahul

  • Verified answer
    Wouter Madou Profile Picture
    3,392 on at

    Hi,

    I would not use Jscript but rather use a business rule for your form instead of Jscript.

    more info:

    www.microsoft.com/.../create-business-rules-and-recommendations-to-apply-logic-in-a-form.aspx

    Set scope to your form.

    Add option set option others.

    Make field mandatory.

    otherwise make field invisible/readonly.

  • Community Member Profile Picture
    on at

    Thank you all

  • Verified answer
    Community Member Profile Picture
    on at

    Use below code:

    //if the user chooses from the option other job title 
    //enable other job title field
    //make other job title mandatory
    //else if the user chooses one of the options make other job title read only
    function EnableOtherJobTitle(){
    var jobtitle= Xrm.Page.getAttribute("new_jobtitle").getValue();
    	if (jobtitle ==100000004)
    	{
    		Xrm.Page.getAttribute("new_otherjob").setRequiredLevel("required");
    	}
    	else 
    	{
    		Xrm.Page.getControl("new_otherjob").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

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 March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans