Wednesday, December 26, 2012

The import has failed because component new_entityName of type 1 is not declared in the solution file as a root component. To fix this, import again using the XML file that was generated when you exported the solution.

while i was importing a solution by adding a part of the xml for a new entity to the customization.xml file.

what i did is , i just added the entity tag section <Entity> ... </Entity> to the customization.xml file.
then imported. so i got the below error details after downloading the file and seeing...
"The import has failed because component new_entityName of type 1 is not declared in the solution file as a root component. To fix this, import again using the XML file that was generated when you exported the solution."

this says the clear thing that we must add the "new_entityName" to the solution.xml file and declare as a root component.

so open the corresponding solution.xml file and search for the "<RootComponents>" tag and add the below with the tags <RootComponents> and </RootComponents>.
<RootComponent type="1" schemaName="new_entityName" />

now zip the files and try to import , it should import smoothly.

Regards,
yes.sudhanshu

Friday, December 21, 2012

Full name , first name, last name in ms crm in contact

this below observation for contact related to the first name, last name and full name.

normally we know the full name is the primary filed and the value will be automatically combined from first name and last name. last name is business required in the system.

what i experienced is, i was pushing the value by interface code to the full name while creating the contact record. but the value was missing from the full name. (note: i was not pushing sny value to first name and last name).

why this was happening?
as above, the full name is the combined value from full name and last name, so if both are blank then full name is blank. and this happens while saving the record by the system.

so when i was pushing the value to the full name and not to first name and last name (so first name and last name were blank), so the full name were getting updated from first name and last name and was result as blank.

Regards,
yes.sudhanshu
 

currency logic in ms crm 2011

just putting my observations here...
this is on basis of the currency filed type in MS CRM 2011
1. when we create one currency field, the currency lookup will we will get created and two fields get created one with extra as (base)
2. if you just add the currency fields (not the one with Base) and do preview page you will see the field as just a common text field (normally the currency symbol should come)
below image Inventories is the currency field

3. if you just put the Currency look up and select the currency the currency symbol will be populated in the currency filed.
see in the below image
4. if you create from CRM its fine and things will work proper if you assign any value to the currency field(not lookup) so currency symbol(ex $) value will come automatically .
5. how if you have some interface program which is creating the record?
    a. if you create the record and you push any value to the currency field(not look up) then its fine , things are ok
    b. but how if you did not put the value ,means is you have n number of currency fields but none of the fields has any value, then in this scenario, all the currency fields will be shown as textbox, so no currency symbol.
    Why this happened?
cuz, the currency look up field has not been assigned any value there so its showing as text field and if you add any value to the currency(not llok up) field you will get error, 1st assign the currency look up.
   how to solve?
so to hit this, you just get the currency value and assign in the lookup, so that the currency symbol will be shown in the currency fields and teh value can be added. below code is to fetch the currency guid from the system, that configured.

public static Guid GetDefaultCurrencyID(IOrganizationService service)
        {
            Guid CurrencyGuid = Guid.Empty;
 
            QueryExpression query = new QueryExpression(TransactionCurrency.EntityLogicalName);
            query.ColumnSet = new ColumnSet(new string[] { "transactioncurrencyid" });
            query.Orders.Add(new OrderExpression("createdon", OrderType.Ascending));
 
            try
            {
                EntityCollection oEntityCollection = service.RetrieveMultiple(query);
                if (oEntityCollection.Entities.Count > 0)
                {
                    CurrencyGuid = (Guid)oEntityCollection.Entities[0].Id;
                }
            }
            catch (Exception ex)
            {
                Util.ThrowException(ex);
            }
 
            return CurrencyGuid;
        }

hope this will help to anyone in any corner....

today is doomsday... if we pass this day , it will help to many more :P

Regards,
yes.sudhanshu

Sunday, December 9, 2012

Quick way to get the ID(GUID) of record, Dirty Fields in the form and Scema names displayed for each fields in MS CRM 2011

ID(GUID) of Record
the below link really give an awesome way to fetch the ID(GUID) of a record which we mostly need, for any unit testing or other requirements...

http://blog.sonomapartners.com/2012/08/javascript-bookmark-series-part-2.html
script for this is

javascript: var id = frames[0].Xrm.Page.data.entity.getId(); if (id) { clipboardData.setData("Text", id.toString()); alert(id); } else { alert('No id yet!'); }

 Dirty Fields in MS CRM Form
 
use this idea how to fetch the dirty fields(fields that has been changed in the form) from MS CRM form...
script is as below
javascript:var message="The following fields are dirty: \n";window.frames[0].Xrm.Page.data.entity.attributes.forEach(function(attribute,index){if(attribute.getIsDirty()==true){message+="\u2219 "+attribute.getName()+"\n";}});alert(message);
 Get Schema Names use the below link to get the way to find the schema names of the fileds on the form..
script is as below
javascript:frames[0].Xrm.Page.ui.controls.forEach(function(a){a.setLabel(a.getName())});
 how to put in Favorite bar and use it...
just browse to any of the crm pages...
then click Favorites -> Add to Favorite
now go to Favorite and the saved one and right click and then properties...
then in the URL , update the above JS code for diff requirements... and save
 
then when u need this requirement, open the record, then do ctrl + N (to get the Fav bar), then click the item... and it will prompt you the result...
then just click on that aleart window and do ctrl + C(copy command), then paste in notepad to get the result...
 
thats it...
:)

 

Wednesday, December 5, 2012

Sample function using SetStateRequest to deactivate record ms crm 2011

below is the code to deactive the records associated to a particular record.
also the 2nd function is used to deactivate a particular record...

//Diactivate all the Associated Records of the primary records
        public static void DiactivateAllAssociatedRecords(IOrganizationService service, Guid primaryEntityId,
            String relatedEntityName, String lookupName)
        {
            try
            {
                //first get all the GUIDs as per the primaryEntityId
                #region //build the query
                ConditionExpression condition1 = new ConditionExpression();
                condition1.AttributeName = lookupName;
                condition1.Operator = ConditionOperator.Equal;
                condition1.Values.Add(primaryEntityId);
 
                FilterExpression filter1 = new FilterExpression();
                filter1.Conditions.Add(condition1);
 
                QueryExpression query = new QueryExpression();
                query.EntityName = relatedEntityName;
                query.ColumnSet = new ColumnSet(true);
                query.Criteria.AddFilter(filter1);
                #endregion
 
                EntityCollection ecResult = service.RetrieveMultiple(query);
                if (ecResult != null && ecResult.Entities.Count > 0)
                {
                    foreach (Entity eResult in ecResult.Entities)
                    {
//this is the next function called.....
                          DiactivateRecord(service, eResult);
                    }
                }
            }
            catch (SoapException spex)
            {
                throw new Exception("Interface : " + spex.StackTrace);
            }
            catch (Exception ex)
            {
                throw new Exception("Interface : " + ex.StackTrace);
            }
        }

 

//diactivate the record now
        public static void DiactivateRecord(IOrganizationService service, Entity eResult)
        {
            try
            {
                SetStateRequest setState = new SetStateRequest();
                setState.EntityMoniker = new EntityReference(eResult.LogicalName, eResult.Id);
                setState.State = new OptionSetValue();
                setState.State.Value = 1;
                setState.Status = new OptionSetValue();
                setState.Status.Value = -1;
                SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState);
            }
            catch (SoapException spex)
            {
                throw new Exception("Interface : " + spex.StackTrace);
            }
            catch (Exception ex)
            {
                throw new Exception("Interface : " + ex.StackTrace);
            }
        }

 NOTE: We Can not Deactivate the Address records as there is no option for that... if we do, it will throw the below exception....
"The 'SetStateDynamicEntity' method does not support entities of type 'customeraddress'."

Regards,
Sudhanshu