Ever encounter problem is cascading drop down?
Cascading in different level ? or maybe just one level.
Using this script.
*Note put this script function cascadingDropdown on the field that onchange to trigger the cascade.
Javascript Eg.
//Function to put in toward field trigger onchange
function cascadingDropdown() {
var Saving = Xrm.Page.data.entity.attributes.get("vw_saving").getValue();
var SavingType = "vw_savingtype";
var picklistTwo = Xrm.Page.getControl(SavingType);
var picklistTwoAttribute = picklistTwo.getAttribute();
if (picklistTwo.flag == true) {
picklistTwo.clearOptions();
var origOptions = picklistTwo.originalPicklistValues;
for (var i = origOptions.length - 1; i >= 0; i--) {
if (origOptions[i].text != "") {
picklistTwo.addOption(origOptions[i]);
}
}
}
else {
picklistTwo.originalPicklistValues = picklistTwoAttribute.getOptions();
picklistTwo.flag = true;
}
var picklistTwoOptions = picklistTwoAttribute.getOptions();
switch (Saving) {
case true:
for (var i = picklistTwoOptions.length - 1; i >= 0; i--) {
if (picklistTwoOptions[i].value != null && picklistTwoOptions[i].value != "") {
var optionText = picklistTwoOptions[i].text;
var optionValue = picklistTwoOptions[i].value;
//Remove these values (This is the problem with hard code)
//U can change the code to get the value too. It depends.
if (optionText == "Negotiation" || optionText == "Discount" || optionText == "Contracting Strategy" || optionText == "Online Bidding (OLB)") {
picklistTwo.removeOption(optionValue);
}
//END: EOS Selection
}
}
break;
case false:
for (var i = picklistTwoOptions.length - 1; i >= 0; i--) {
if (picklistTwoOptions[i].value != null && picklistTwoOptions[i].value != "") {
var optionText = picklistTwoOptions[i].text;
var optionValue = picklistTwoOptions[i].value;
//Remove these values
if (optionText == "Joint Tender" || optionText == "Integrated Tender") {
picklistTwo.removeOption(optionValue);
}
//END: CS Selection
}
}
break;
default:
break;
}
}
End.
The bad thing about this script is if u have thousand or hundred of cascading record, u need to hardcore the value one by one and it takes a lot of time and script line.
For what i suggest if there are thousand or more than thousand of cascading record, better make use of the lookup toward entity. By using lookup it wont be consuming much time in scripting or work with the cascading part.
CRM 2011 Cascading Drop Down
0 commentsPosted by Unknown at 6/28/2012 05:28:00 pm
Labels: CRM 2011
CRM 2011 Date Time Duration
0 comments
Date Time Duration between two field.
*Note duration field is in decimal type. That mean the calculation can calculate until decimal point. At here u can set the amount of decimal point u want to see at the field.
Javascript Eg.
function getAging() {
var Answer = 0;
var AgingStartTime = Xrm.Page.data.entity.attributes.get("FieldName").getValue();
var AgingEndTime = Xrm.Page.data.entity.attributes.get("FieldName").getValue();
if (AgingStartTime != null) {
//Date time duration different between today and AgingStartTime
var today = new Date();
Answer = (today - AgingStartTime) / 1000 / 60 / 60 / 24;
//Date time duration different between AgingStartTime and AgingEndTime
Answer = (
AgingStartTime -
AgingEndTime ) / 1000 / 60 / 60 / 24;
}
else { Answer = null; }
//Which field to put the answer record to.
Xrm.Page.data.entity.attributes.get("FieldName").setValue(Answer);
}
End.
Posted by Unknown at 6/28/2012 05:12:00 pm
Labels: CRM 2011
CRM 2011 Focus To A Certain Field
0 comments
Javascript to focus to particular field
Xrm.Page.ui.controls.get("FieldName").setFocus();
Posted by Unknown at 6/28/2012 04:52:00 pm
Labels: CRM 2011
CRM 2011 Set Field Into Mandatory Field
0 comments
Javascipt to set the field into mandatory field.
Javascript Eg.
function setResponsible() {
//Status act as picklist to trigger the field to become mandatory
var status = Xrm.Page.getAttribute("vw_status").getValue();
//setRequiredLevel to set as mandatory or other (none, required and recommended)
if (status == 2) { Xrm.Page.getAttribute("vw_staffresponsibleid").setRequiredLevel("required"); }
else { Xrm.Page.getAttribute("vw_staffresponsibleid").setRequiredLevel("none"); }
}
End.
Posted by Unknown at 6/28/2012 04:50:00 pm
Labels: CRM 2011