The ConditonOperator.Equal requires 1 value, not 0.


This error is recieved when for ConditionExpression, we would have set

AttributeName, Operator properties but haven’t set Values property.

The below code would result in the ConditonOperator.Equal requires 1 value, not 0 error.

ConditionExpression myCon = new ConditionExpression();
myCon.AttributeName = “createdbyname”;
myCon.Operator = ConditionOperator.Equal;
//line commented for reproducing error
//myCon.Values = new object[] { “username” };

Bye..

Understanding LookUp In CRM


Hi find out this nice post about LookUp by JimWang.

http://jianwang.blogspot.com/2008/05/mysterious-crm-lookup-i.html

Do Check it ..

Bye..

Error 0x80041110 QueryByAttribute must specify a non-empty attribute array in CRM


This error occurs when using the QueryByAttribute class we are not setting the Attributes and Values Property.

 

Just like the below code

 

Say we want to have the names of all the accounts,

 

ColumnSet myCols=new ColumnSet();

            myCols.Attributes=new string[] {“name”};

   QueryByAttribute myQA = new QueryByAttribute();

            myQA.EntityName = EntityName.account.ToString();

            myQA.ColumnSet = myCols ;           

            BusinessEntityCollection myBCColl2= myService.RetrieveMultiple(myQA);

 

However we will get error in this case because we haven’t specified Attributes and Values property. So we need to specify those properties.

 

            myQA.Attributes = new String[] { “statuscode” };

            myQA.Values=new object[] {“1”};

 

Otherwise we could use QueryByExpression class for that

 

            ColumnSet myCols=new ColumnSet();

            myCols.Attributes=new string[] {“name”};

 

            QueryExpression myQE = new QueryExpression();

            myQE.EntityName = EntityName.account.ToString();

            myQE.ColumnSet = myCols;

 

            BusinessEntityCollection myBCColl1 = myService.RetrieveMultiple(myQE);

 

 

Bye ..

Adding custom menu and button to custom entity through ISV.CONFIG


To add custom menu and button to Entity form,

Go to Customizations-Export Customizations-Select ISV.CONFIG.

Open the customizations.xml file and add the following xml tags to it

<Entity name=new_customentity>

          <MenuBar>

            <CustomMenus>

              <Menu>

                <Titles>

                  <Title LCID=1033 Text=My Custom Menu>

                  </Title>

                </Titles>

                <MenuItem Url=http://www.microsoft.com PassParams=0 WinMode=1>

                  <Titles>

                    <Title LCID=1033 Text=Coming Soon ..>

                    </Title>

                  </Titles>

                </MenuItem>

              </Menu>

            </CustomMenus>

          </MenuBar>

          <ToolBar>

            <Button AvailableOffline=false ValidForCreate=1 ValidForUpdate=1 Url=http://www.google.co.in>

              <Titles>

                <Title LCID=1033 Text=My Custom Button… />

              </Titles>

              <ToolTips>

                <ToolTip

                 LCID=1033

                 Text=My custom button tooltip     />

              </ToolTips>

            </Button>

          </ToolBar>

        </Entity>

That’s it ..

SetState for CustomEntity in CRM


For every new custom entity created in CRM corresponding SetStateCustomEntityNameRequest and SetStateCustomEntityNameResponse class gets created which we can use to set their status.

 

In the below example we have set the status inactive for our custom country entity records.

 

 

 SetStateNew_CountryRequest myCountryRequest = new SetStateNew_CountryRequest();

                // guid of the record to be deactivated

                myCountryRequest.EntityId = new Guid(“3AE10D22-60E4-DD11-9D85-00164145E126”);

                // statecode – 1 , statecodename- Inactive, statuscode – 2, statuscodename – Inactive

                // statecode – 0 , statecodename- Inactive, statuscode – 1, statuscodename – Inactive

                myCountryRequest.New_CountryState = New_CountryState.Inactive;

                myCountryRequest.New_CountryStatus = 2;

                SetStateNew_CountryResponse myCountryResponse = (SetStateNew_CountryResponse)crmService.Execute(myCountryRequest);

 

Bye ..

Programmatically updating the status of workflow logs using TargetUpdateWorkflowLog class in CRM 4.0


I was just trying out if changing the status for the workflow is possible programmatically. Well this is something I tried.

Created a function which would take primary key(guid) of the entity intance and would return all the workflow logs for that entity instance having status as “In Progress” and changing their status to “Failed”

 

The function to retrieve all the workflowlog id

 

private ArrayList   GetInProgressWorkflowLogIDForEntity(CrmService crmService, string EntityId)

        {

            QueryExpression myQuery = new QueryExpression();

            ColumnSet myCols = new ColumnSet();

            // to retireve workflowlogid

            myCols.Attributes = new String[] { “workflowlogid” };

            myQuery.ColumnSet = myCols;

            myQuery.EntityName = EntityName.workflowlog.ToString();

          

            ConditionExpression myCondtionExpression1 = new ConditionExpression();

            // entityinstance id against which workflowlog is running

            myCondtionExpression1.AttributeName = “regardingobjectid”;

            myCondtionExpression1.Operator = ConditionOperator.Equal;

            myCondtionExpression1.Values = new object[] {EntityId };

            // Status of workflowlog

            // Failed – 3

            // Succeeded – 2

            // In Progress – 1

            ConditionExpression myCondtionExpression2 = new ConditionExpression();

            myCondtionExpression2.AttributeName = “In Progress”;

            myCondtionExpression2.Operator = ConditionOperator.Equal;

            myCondtionExpression2.Values = new object[] { “1” };

 

            FilterExpression myFilterExpression = new FilterExpression();

            myFilterExpression.FilterOperator = LogicalOperator.And;

            myFilterExpression.Conditions = new ConditionExpression[] { myCondtionExpression1, myCondtionExpression2 };

 

            myQuery.Criteria = myFilterExpression;

 

            BusinessEntityCollection myBE=crmService.RetrieveMultiple(myQuery);

 

            ArrayList myWFLogList = new ArrayList();

            foreach (BusinessEntity myBusinessEntity in myBE.BusinessEntities)

            {

                workflowlog myWFLogId = (workflowlog)myBusinessEntity;

                myWFLogList.Add(myWFLogId.workflowlogid.Value.ToString());

 

            }

            return myWFLogList;    

        }

 

 

 

 

Using TargetUpdateWorkflowLog class

 

 

ArrayList myWorkflowLog=GetInProgressWorkflowLogIDForEntity(crmService, “55B93CBB-99E3-DD11-9D85-00164145E126”);

 

                foreach (String wfLogId in myWorkflowLog)

                {

                    TargetUpdateWorkflowLog myUpdateWorkflow = new TargetUpdateWorkflowLog();

                    myUpdateWorkflow.WorkflowLog = new workflowlog();

                    myUpdateWorkflow.WorkflowLog.workflowlogid = new Key();

                    // workflowlogid of workflow having status as In Progress

                    // to be changed to Failed – 3

                    myUpdateWorkflow.WorkflowLog.workflowlogid.Value = new Guid(wfLogId);

 

                    // Failed – 3

                    // Succeeded – 2

                    // In Progress – 1

                    myUpdateWorkflow.WorkflowLog.status = new Picklist();

                    myUpdateWorkflow.WorkflowLog.status.name = “Failed”;

                    myUpdateWorkflow.WorkflowLog.status.Value = 3;

 

                    UpdateRequest myRequest = new UpdateRequest();

                    myRequest.Target = myUpdateWorkflow;

 

                    UpdateResponse myRes = (UpdateResponse)crmService.Execute(myRequest);

                }