in

Paul Rausch

May 2008 - Posts

  • CRM QueryExpression Grouping Conditions

    I had a scenario the other day where I need to use the CRM SDK to do a query simlar to this 'WHERE column1 = value AND (column2=value1 OR column2=value2)' , this was pretty easy to accomplish once I understood difference between Filters and Conditions on the QueryExpression object.  Here is how the previous query maps out to Conditions and Filters.

    column1 = value  //is a condition
    (column2=value1 OR column2=value2) //is a filter

    So basically the way to build it is to create a condition expression for  (column2=value1 OR column2=value2) and add that as a filter expression to the top level expression.  The following code demonstrates.

            Dim column1Condition As New CRMService.ConditionExpression
            column1Condition.AttributeName = "column1"
            column1Condition.Operator = CRMService.ConditionOperator.Equal
            column1Condition.Values = New Object() {value}

            Dim column2Value1Condition As New CRMService.ConditionExpression
            column2Value1Condition.AttributeName = "column2"
            column2Value1Condition.Operator = CRMService.ConditionOperator.Equal
            column2Value1Condition.Values = New Object() {value1}

            Dim column2Value2Condition As New CRMService.ConditionExpression
            column2Value2Condition.AttributeName = "column2"
            column2Value2Condition.Operator = CRMService.ConditionOperator.Equal
            column2Value2Condition.Values = New Object() {value2}       

            Dim qe As New CRMService.QueryExpression

            Dim secondLevelFilter As CRMService.FilterExpression = New CRMService.FilterExpression
            secondLevelFilter.FilterOperator = CRMService.LogicalOperator.Or
            secondLevelFilter.Conditions = New CRMService.ConditionExpression {column2Value1Condition, column2Value2Condition}

            Dim topLevelFilter As CRMService.FilterExpression = New CRMService.FilterExpression
            topLevelFilter.FilterOperator = CRMService.LogicalOperator.And
            topLevelFilter.Conditions = New CRMService.ConditionExpression {column1Condition}
            topLevelFilter.Filters = New CRMService.FilterExpression {secondLevelFilter}

            qe.Criteria = topLevelFilter

  • Embedding a CRM view in a form using an IFrame

    I recently created a custom child entity that I wanted to show both on the left side navigation and on the parent entity form itself in an Iframe.  Here are the steps I took to accomplish that.  This will also work for non-custom entity views that you would like to embed into a form.  This will display a full view in the contained Iframe with all the same button navigation as if you went the view directly in a new window.

    Step 1 :
    Add an IFrame to your form and set the source to about:blank.

    Step 2:
    Open a parent entity in a detail view.  Select Ctl-N to open the detail view in a new browser, now view the source and find the view you want to embed in the left hand navigation.  Once you locate that in the HTML source grab the contentarea references in the loadArea("") function.

    Step 3:
    Add the following script to the onload event for the form that contains the Iframe(parent entity).  Replace the 'contentarea' with the value from Step 2.

    document.all.IFRAME_PartsFrame.src="/sfa/conts/areas.aspx?oId=" + crmForm.ObjectId + "&oType=" + crmForm.ObjectTypeCode + "&security=852023&tabSet=contentarea";


     

     

    Posted May 01 2008, 10:32 AM by prausch with no comments
    Filed under:
Inetium, LLC. Disclaimer