Skip to main content

Notifications

Announcements

No record found.

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)

Posted on by Microsoft Employee

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

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: 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)

    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);
    	}
    }


  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: 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)

    Thank you all

  • Verified answer
    Wouter Madou Profile Picture
    Wouter Madou 3,392 on at
    RE: 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)

    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.

  • Rahul G J Profile Picture
    Rahul G J 605 on at
    RE: 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)

    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
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: 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)

    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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans