Wednesday, July 27, 2011

CRM 2011 - Filter Views Using Java Script

Call the function Form Load....

function LoadParentMemberAsFullMemberType() {

var viewId = "{65EC9B45-EE81-4F89-BAF6-E8603FF8E1E4}";
var entityName = "account";
var viewDisplayName = "Membership Types";
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='account'>" +
"<all-attributes/>" +
" <link-entity name='mship_membershiptype' from='mship_membershiptypeid' to='mship_membershiptypeid' > " +
" <filter type='and'>" +
"<condition attribute='mship_type' operator='eq' value='Full Member' />" +
" </filter> " +
" </link-entity>" +

"</entity>" +

"</fetch>";



//build grid layout
var layoutXml = "<grid name='resultset' " +
"object='1' " +
"jump='account' " +
"select='1' " +
"icon='1' " +

"preview='1'>" +

"<row name='result' " +

"id='accountid'>" +


"<cell name='mship_companyname' " +
"width='300' />" +
"<cell name='accountnumber' " +

"width='300' />" +
"<cell name='mship_membershiptypeid' " +

"width='300' />" +


"</row>" +

"</grid>";




//add new view view
Xrm.Page.getControl("parentaccountid").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);//Attach to the feild
// Chech The Chenged Field
var membershiptype = crmForm.all["parentaccountid"];
membershiptype.setAttribute("disableViewPicker", "1")


}

No comments:

Post a Comment