Modify Add Existing View

http://danielcai.blogspot.ie/2011/12/filtered-lookup-for-existing-button-of.html

For rollup 12 issues:

http://www.magnetismsolutions.com/blog/paulnieuwelaar/2013/02/04/filter-n-n-add-existing-lookup-dynamics-crm-2011-rollup-12

FILTERING THE RESULTS USING THE SOAP END POINT


//filters an add existing lookup view (1:N)
function addExistingFromSubGridCustom (gridTypeCode, gridControl, fetch, layout, viewName) {
    var viewId = "{1DFB2B35-B07C-44D1-868D-258DEEAB88E2}"; // a dummy view ID
    var relName, roleOrd;
    if (typeof (gridControl.GetParameter) === "function") { //post rollup 12
        relName = gridControl.GetParameter("relName");
        roleOrd = gridControl.GetParameter("roleOrd");
    }
    else { //pre rollup 12
        relName = gridControl.getParameter("relName");
        roleOrd = gridControl.getParameter("roleOrd");
    }

    //creates the custom view object
    var customView = {
        fetchXml: fetch,
        id: viewId,
        layoutXml: layout,
        name: viewName,
        recordType: gridTypeCode,
        Type: 0
    };

    //pops the lookup window with our view injected
    var lookupItems = LookupObjects(null, "multi", gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]);

    //once the lookup window is closed, we need the parent record ID and ETC before associating selected records
    if (lookupItems && lookupItems.items.length > 0)
	{
        var parentId;
        var parentTypeCode;
        if (typeof (GetParentObject) == "function")
		{ //post rollup 12 has its own function to get this
            var parent = GetParentObject();
            parentId = parent.id;
            parentTypeCode = parent.objectTypeCode;
        }
        else
		{ //pre rollup 12 still needs to use the old way
            var parent = typeof (crmFormSubmit) == "undefined" ? $get("crmFormSubmit") : crmFormSubmit; //according to daniels blog crmFormSubmit should already be defined, but it's not...
            if (parent) {
                parentId = parent.crmFormSubmitId.value;
                parentTypeCode = parent.crmFormSubmitObjectType.value;
            }
            else {
                parentId = window.parent.crmFormSubmit.crmFormSubmitId.value;
                parentTypeCode = window.parent.crmFormSubmit.crmFormSubmitObjectType.value;
            }
        }

        //associates the selected records
        AssociateObjects(parentTypeCode, parentId, gridTypeCode, lookupItems, IsNull(roleOrd) || roleOrd == 2, "", relName);
    }
}

//filters the Emision Point 1:N lookup view from Amendment to show only Emision Points Regarding the ammendment!!
function filterAddExistingAmpoints (gridTypeCode, gridControl, primaryEntityName, entityID)
{
	var cols = ["amendment"];
	var retrievedGroup = CrmServiceToolkit.Retrieve(primaryEntityName, entityID, cols);

    //fetch to retrieve filtered data
    var fetch = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
        "  <entity name='amemissionpoint'>" +
        "    <attribute name='amemissionpointid' />" +
		"    <attribute name='name' />" +        
		"    <attribute name='shortcode' />" +
		"    <attribute name='group' />" +		
		"    <attribute name='emissionpointtype' />" +		
		"    <attribute name='createdon' />" +
        "    <order attribute='missionpointtype' descending='false' />" +
        "    <filter type='and'>" +
        "      <condition attribute='amendment' operator='eq' value='" + retrievedGroup.getValue('amendment') +"' />" +
	    "    </filter>" +
        "  </entity>" +
        "</fetch>";

    //columns to display in the custom view (make sure to include these in the fetch query) 
    var layout = "<grid name='resultset' object='1' jump='amemissionpointid' select='1' icon='1' preview='1'>" +
        "  <row name='result' id='amemissionpointid'>" +
        "    <cell name='name' width='200' />" +
		"    <cell name='shortcode' width='30' />" +
		"    <cell name='emissionpointtype' width='100' />" +
		"    <cell name='createdon' width='100' />" +
		"    <cell name='group' width='100' />" +
        "  </row>" +
        "</grid>";

    addExistingFromSubGridCustom(gridTypeCode, gridControl, fetch, layout, "Filtered Emision Points");
}

To hide the lookup view button “new” use the following UNSUPPORTED solution.

	//Removing the New button from lookup.
		var lookupControl = Sys.Application.findComponent(lookupname);
		 
		 if (lookupControl != null)
		{
			 lookupControl._element._behaviors[0].AddParam("ShowNewButton", 0);
		 }
About these ads

One thought on “Modify Add Existing View

  1. mhernandezepa

    To disable the Looup Dialog option sets for View Selection and Entity selection we have to modify the LookupObject function.

    // Definition of LookupObjects()
    //LookupObjects(lookupField, lookupStyle["single"/"multi"], lookupTypes, lookupBrowse, bindingColumns, additionalParams, showNew, showProp, bPopulateLookup, defaultType, searchString,
    //dataProviderOverride, defaultViewId, customViews, filterRelationshipId, rId, rType, rDependAttr, allowFilterOff, disableQuickFind, disableViewPicker, viewsIds,””)

    Example

    var lookupItems = LookupObjects(null, “multi”, gridTypeCode, 0, null, “”, null, null, null, null, null, null, viewId, [customView], null, null, null, 1, 1, null, 1);

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s