Answered by:
CRM2013 - Javascript - setRequiredLevel does not work along with setLabel

Question
-
Here is the sample scenario.....
I have two fields no form
1) Person category [optionsset with options- Student, Employed, Other etc]
2) CName [Single line of text]
Javascript implmentation
If user selects option "Student" then label of CName field is changed to "Student" and same field become becomes the mandatory field.
If user selects option "Employed" then label of CName field is changed to "Employed" and same field become becomes the mandatory field.
If user selects option "Other" then label of CName field is not changed and same field stays non-required.
Xrm.Page.getControl('pp_cname').setRequiredLevel('required');
Xrm.Page.getControl('pp_cname').setLabel('Student');
I even tried
Xrm.Page.getControl('pp_cname').setLabel('Student');
Xrm.Page.getControl('pp_cname').setRequiredLevel('required');
In here label is changed correctly but setRequiredLevel is not working correctly and what I mean by that is "*" is not displayed against that field.
Any help is appreciated
Thanks
MonalisaTuesday, February 4, 2014 5:49 AM
Answers
-
Hi
Check without writing javascript..
http://mahenderpal.wordpress.com/tag/ms-crm-2013-new-feature/
Hope this helps
- Proposed as answer by SravaniRN459 Tuesday, February 4, 2014 8:36 AM
- Marked as answer by Jamie MileyModerator Tuesday, February 4, 2014 3:25 PM
Tuesday, February 4, 2014 6:36 AM -
Hi,
setRequiredLevel is a method of Xrm.Page.data.entity, not of Xrm.Page.ui.controls.get
so the correct code is;
Xrm.Page.getControl('pp_cname').setLabel('Student'); Xrm.Page.getAttribute('pp_cname').setRequiredLevel('required');
My blog: www.crmanswers.net - Rockstar 365 Profile
- Proposed as answer by Guido PreiteMVP Tuesday, February 4, 2014 7:01 AM
- Unproposed as answer by Mon2014 Tuesday, February 4, 2014 7:26 AM
- Marked as answer by Jamie MileyModerator Tuesday, February 4, 2014 3:25 PM
Tuesday, February 4, 2014 7:01 AM
All replies
-
Hi
Check without writing javascript..
http://mahenderpal.wordpress.com/tag/ms-crm-2013-new-feature/
Hope this helps
- Proposed as answer by SravaniRN459 Tuesday, February 4, 2014 8:36 AM
- Marked as answer by Jamie MileyModerator Tuesday, February 4, 2014 3:25 PM
Tuesday, February 4, 2014 6:36 AM -
I cannot use business rule as it does not allow to change label of the field
Thanks
Tuesday, February 4, 2014 6:41 AM -
This looks like bug in MS Dynamics CRM 2013
Tuesday, February 4, 2014 6:42 AM -
Hi,
setRequiredLevel is a method of Xrm.Page.data.entity, not of Xrm.Page.ui.controls.get
so the correct code is;
Xrm.Page.getControl('pp_cname').setLabel('Student'); Xrm.Page.getAttribute('pp_cname').setRequiredLevel('required');
My blog: www.crmanswers.net - Rockstar 365 Profile
- Proposed as answer by Guido PreiteMVP Tuesday, February 4, 2014 7:01 AM
- Unproposed as answer by Mon2014 Tuesday, February 4, 2014 7:26 AM
- Marked as answer by Jamie MileyModerator Tuesday, February 4, 2014 3:25 PM
Tuesday, February 4, 2014 7:01 AM -
Even Xrm.Page.getAttribute('pp_cname').setRequiredLevel('required'); does not work in this scenario (when changing the label)
Tuesday, February 4, 2014 7:25 AM -
Hi
Try this code..
function functionName()
{
var vOptionsetType = Xrm.Page.data.entity.attributes.get("new_optionset");
yValue = vOptionsetType.getSelectedOption().text;
if (yValue == "Student") //Employed, Other
{
Xrm.Page.getAttribute("new_textfield").setRequiredLevel("required");
}
}Hope this helps..
Tuesday, February 4, 2014 8:39 AM -
Thanks Suresh
But Xrm.Page.getAttribute("new_textfield").setRequiredLevel("required"); is not working when I am changing the label of the same field at the same time
Tuesday, February 4, 2014 8:54 AM -
Hi
finally... Its working when changing the label of same field..
function GetRelated()
{
var vOptionsetType = Xrm.Page.data.entity.attributes.get("new_Optionset");
yValue = vOptionsetType.getSelectedOption().text;
if (yValue == "Student")
{
lbl(yValue );
Xrm.Page.getAttribute("new_textfield").setRequiredLevel("required");
}
}
function lbl(yValue )
{
if(yValue=="Student")
{
Xrm.Page.getControl("new_textfield").setLabel("TextStudent");
}
}Hope this helps..
- Proposed as answer by Suresh Sorde Tuesday, February 4, 2014 9:45 AM
- Edited by Suresh Sorde Tuesday, February 4, 2014 11:06 AM
Tuesday, February 4, 2014 9:32 AM