Wednesday, May 7, 2014

Entity statecodes and statuscodes MS CRM 2011 and MS CRM 2013

List of statecodes and statuscodes of the commonly used entities

Entity
Status (statecode)
Associated Status Reason (statuscode)
Account (account)
0 Active
1 Active
1 Inactive
2 Inactive
Activity (activitypointer)
0 Open
1 Open
1 Completed
2 Completed
2 Canceled
3 Canceled
3 Scheduled
4 Scheduled
Appointment (appointment)
0 Open
1 Free
2 Tentative
1 Completed
3 Completed
2 Canceled
4 Canceled
3 Scheduled
5 Busy
6 Out of Office
Article (kbarticle)
1 Draft
1 Draft
2 Unapproved
2 Unapproved
3 Published
3 Published
Campaign (campaign)
0 Active
0 Proposed
1 Ready To Launch
2 Launched
3 Completed
4 Canceled
5 Suspended
Campaign Activity (campaignactivity)
0 Open
0 In Progress
1 Proposed
4 Pending
5 System Aborted
6 Completed
1 Closed
2 Closed
2 Canceled
3 Canceled
Campaign Response (campaignresponse)
0 Open
1 Open
1 Closed
2 Closed
2 Canceled
3 Canceled
Case (incident)
0 Active
1 In Progress
2 On Hold
3 Waiting for Details
4 Researching
1 Resolved
5 Problem Solved
2 Canceled
6 Canceled
Case Resolution (incidentresolution, notcustomizable)
0 Open
1 Open
1 Completed
2 Closed
2 Canceled
3 Canceled
Contact (contact)
0 Active
1 Active
1 Inactive
2 Inactive
Contract (contract)
0 Draft
1 Draft
1 Invoiced
2 Invoiced
2 Active
3 Active
3 On Hold
4 On Hold
4 Canceled
5 Canceled
5 Expired
6 Expired
Contract Line (contractdetail)
0 Existing
1 New
1 Renewed
2 Renewed
2 Canceled
3 Canceled
3 Expired
4 Expired
Currency (transactioncurrency)
0 Active
0 Active
1 Inactive
1 Inactive
Discount (discounttype)
0 Active
100001 Active
1 Inactive
100002 Inactive
E-mail (email)
0 Open
1 Draft
8 Failed
1 Completed
2 Completed
3 Sent
4 Received
6 Pending Send
7 Sending
2 Canceled
5 Canceled
Fax (fax)
0 Open
1 Open
1 Completed
2 Completed
3 Sent
4 Received
2 Canceled
5 Canceled
Invoice (invoice)
0 Active
1 New
2 Partially Shipped
4 Billed
5 Booked (applies to services)
6 Installed (applies to services)
1 Closed (deprecated)
3 Canceled (deprecated)
7 Paid in Full (deprecated
2 Paid
100001 Complete
100002 Parial
3 Canceled
100003 Canceled
Lead (lead)
0 Open
1 New
2 Contacted
1 Qualified
3 Qualified
2 Disqualified
4 Lost
5 Cannot Contact
6 No Longer Interested
7 Canceled
Letter (letter)
0 Open
1 Open
2 Draft
1 Completed
3 Received
4 Sent
2 Canceled
5 Canceled
Marketing List (list)
0 Active
0 Active
1 Inactive
1 Inactive
Opportunity (opportunity)
0 Open
1 In Progress
2 On Hold
1 Won
3 Won
2 Lost
4 Canceled
5 Out-Sold
Order (salesorder)
0 Active
1 New
2 Pending
1 Submitted
3 In Progress
2 Canceled
4 No Money
3 Fulfilled
100001 Complete
100002 Partial
4 Invoiced
10003 Invoiced
Phone Call (phonecall)
0 Open
1 Open
1 Completed
2 Made
4 Received
2 Canceled
3 Canceled
Price List (pricelevel)
0 Active
100001 Active
1 Inactive
10002 Inactive
Product (product)
0 Active
1 Active
1 Inactive
2 Inactive
Quote (quote)
0 Draft
1 In Progress
1 Active
2 In Progress
3 Open
2 Won
4 Won
5 Out-Sold
3 Closed
5 Lost
6 Canceled
7 Revised
Service Activity (serviceappointment)
0 Open
1 Requested
2 Tentative
1 Closed
8 Completed
2 Canceled
9 Canceled
10 No Show
3 Scheduled
3 Pending
4 Reserved
6 In Progress
7 Arrived
Task (task)
0 Open
2 Not Started
3 In Progress
4 Waiting on someone else
7 Deferred
1 Completed
5 Completed
2 Canceled
6 Canceled

The above table is a reference from this wonderful site.

To reactivate the case use below line of code

SetStateRequest objSetStateRequest = new SetStateRequest();
objSetStateRequest.EntityMoniker = new EntityReference("incident", caseGuid);
objSetStateRequest.State = new OptionSetValue(0); //0=Active
objSetStateRequest.Status = new OptionSetValue(1);//1=In Progress
service.Execute(objSetStateRequest);

To resolve the case use the below line of code

CloseIncidentRequest objCloseIncidentRequest = new CloseIncidentRequest();
objCloseIncidentRequest.Status = new OptionSetValue(5);                        
Entity objEntity=new Entity("incidentresolution");
objEntity.Attributes["subject"]="Resolved";
objEntity.Attributes["incidentid"]=new EntityReference("incident", parentCaseId);
objCloseIncidentRequest.IncidentResolution = objEntity;
service.Execute(objCloseIncidentRequest);

Tuesday, February 25, 2014

How to get Query String parameters from JavaScript


We can easily set up a Javascript function that will retrieve the query string and load an array with the values passed in the query string. Here it is. This function goes into the head section of our page.

var qsParm;
        GetQueryStringParams();

        function GetQueryStringParams() {
            //Holds key:value pairs
            qsParm = new Array();
            //Get querystring from url
            var requestUrl = window.location.search.toString();
            if (requestUrl != '') {
                //window.location.search returns the part of the URL
                //that follows the ? symbol, including the ? symbol
                var query = requestUrl.substring(1);

                //Get key:value pairs from querystring
                var parms = query.split('&');

                for (var i = 0; i < parms.length; i++) {
                    var pos = parms[i].indexOf('=');
                    if (pos > 0) {
                        var key = parms[i].substring(0, pos);
                        var val = parms[i].substring(pos + 1);
                        qsParm[key] = val;
                    }
                }
            }
        }

MS CRM 4.0/2011 : How to get more than 5000 record from CRM database.

Sometimes you required to retrieve all the entity record from database using FETCH and QUERY EXPRESSION but CRM limitation to not retrieve more than 5000 records. The way to retrieve use the below line of code:

public static List<DynamicEntity> GetAllEntityRecords(CrmService service, string entityName, List<ConditionExpression> conditions, ColumnSet columns)
        {
            List<DynamicEntity> records = null;
            try
            {
                QueryExpression query = new QueryExpression();
                query.EntityName = entityName;

                if (columns != null)
                    query.ColumnSet = columns;
                else
                    query.ColumnSet = new AllColumns();

                if (conditions != null && conditions.Any())
                {
                    query.Criteria = new FilterExpression();
                    query.Criteria.FilterOperator = LogicalOperator.And;

                    foreach (var cond in conditions)
                    {
                        query.Criteria.AddCondition(cond);
                    }
                }
                query.PageInfo = new PagingInfo();
                query.PageInfo.Count = 100;
                query.PageInfo.PageNumber = 1;
                query.PageInfo.PagingCookie = null;

                RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
                retrieve.Query = query;
                retrieve.ReturnDynamicEntities = true;

                records = new List<DynamicEntity>();

                while (true)
                {

                    BusinessEntityCollection results = ((RetrieveMultipleResponse)service.Execute(retrieve)).BusinessEntityCollection;
                    if (results.BusinessEntities != null)
                    {
                        foreach (DynamicEntity de in results.BusinessEntities)
                            records.Add(de);
                    }

                    // Check for morerecords, if it returns true.
                    if (results.MoreRecords)
                    {
                        // Increment the page number to retrieve the next page.
                        query.PageInfo.PageNumber++;
                        // Set the paging cookie to the paging cookie returned from current results.
                        query.PageInfo.PagingCookie = results.PagingCookie;
                    }
                    else
                    {
                        // If no more records are in the result nodes, exit the loop.
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return records;
        }

Thursday, January 23, 2014

Resolve C:\fackpath in upload field instead o the full path

For the security reason this fackpath introduced and there is no way to show the actual path instead of the fackpath.

Just one way to replace the fackpath and show only the uploaded file name.

// check for IE's lovely security speil
if(filePath.match(/fakepath/)) {
  // update the file-path text using case-insensitive regex
  filePath = filePath.replace(/C:\\fakepath\\/i, '');
}

To replace the "\" in the URL use the below line of code.


this.value.replace(/\\\\/g, '');


Post data from client to a web service (.asmx, .svc) in C#

If you want to post data from your web application to web service then use the below line of code and change it according your requirement.

ClientSection clientSettings = ConfigurationManager.GetSection("system.serviceModel/client"as ClientSection;
                string address = string.Empty;
                foreach(ChannelEndpointElement endpoint in clientSettings.Endpoints)
                {
                    if (endpoint.Name == "WarrantyXServiceSoap")
                    {
                        address = endpoint.Address.ToString();   
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(address))
                {
                    HttpWebRequest request;
                    string url = WebService URL;
                    string action = "http://tempuri.org/MethodName";

                    request = (HttpWebRequest)WebRequest.Create(url);
                    request.Method = "POST"; // OR "GET" if you want to make a GET request 
                    request.ContentType = "text/xml; charset=utf-8";
                    request.Headers.Add("SOAPAction: " + action);

                    StringBuilder soapRequest = new StringBuilder("");
                    soapRequest.Append("http://www.w3.org/2001/XMLSchema-instance\
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
                    soapRequest.Append("");
                    soapRequest.Append("http://tempuri.org/\
">");
// these are the parameters of web method to pass data from client machine
                    soapRequest.Append("" + _Name + "
");
                    soapRequest.Append("" + Convert.ToBase64String(_BinaryDoc) + "
");
                    soapRequest.Append("" + _ContentType + "
");
                    soapRequest.Append("" + _ID.ToString() + "
");

                    soapRequest.Append("
");
                    soapRequest.Append("
");
                    soapRequest.Append("
");

                    request.ContentLength = soapRequest.ToString().Length;
                    request.KeepAlive = false;
                    request.Timeout = System.Threading.Timeout.Infinite;
                    request.AllowWriteStreamBuffering = false;
                    request.ProtocolVersion = HttpVersion.Version10;
                    request.ServicePoint.ConnectionLeaseTimeout = 600000;
                    request.ServicePoint.MaxIdleTime = 600000;
                    request.Proxy = null;
                    request.ReadWriteTimeout = 600000;
                    request.Accept = "text/xml";

                    using (Stream requestStream = request.GetRequestStream())
                    {
                        using (StreamWriter requestStreamWriter = new StreamWriter(requestStream))
                        {
                            requestStreamWriter.Write(soapRequest.ToString());
                        }
                    }

                    string result = string.Empty;
                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    {
                        StreamReader reader = new StreamReader(response.GetResponseStream());
                        result = reader.ReadToEnd();
                    }

                    var xDoc = XDocument.Parse(result);
                    _createdAnnotation = new Guid(xDoc.Root.Value);

                }

How do I upload large greater than 5MB files to a web service?

I have a web service that takes a serialize string and saves it.
This works fine for "small" files, but once I hit a large size the web service fails and returns "The request failed with HTTP status 404: Not Found."
From what I've seen this appears to be an IIS setting that limits the size of a file that can be posted. I've tried to increase that setting, but I am having trouble determining what setting and where/how one would set it. I am using IIS7 and the webservice is done in .net (asmx).
In the web.config of the web service I have added the following (which seemed to increase the size of file that can be accepted, but not all the way to this setting size)
IIS 6

 <system.web>
     <httpRuntime executionTimeout="999999" maxRequestLength="2097151" />
     ...
  </system.web>
IIS7
   <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="2000000000" />
      </requestFiltering>
    </security>
  </system.webServer>
   
     
       
     
   
 



Sunday, January 19, 2014

LINQ - Concat a column value by a Unique ID

Table 1:

Number               City       
111                         Delhi     
111                         Agra      
112                         Jaipur   
111                         Hapur   
113                         Jodhpur              

Table 2

Number(Unique)  Percent
111                                         10
112                                         20
113                                         30


Output Required

Number                               Cities                             Percent
111                         Delhi ,Agra ,Hapur                           10
112                                         Jaipur                               20
113                                         Jodhpur                            30


By Linq

var varContact = from t2 in Table2.AsEnumerable()
                                    
                 join t1 in Table1.AsEnumerable() on t1.Field("Number") equals t2.Field("Number") into t1t2
                 select new
                 {
                                     Number = t2.Field("Number"),
                     Cities = t1t2.Where(x => x.Field("Number").ToString().Equals(c.Field("Number").ToString())).Select(g => g.Field("City")).Aggregate((i, j) => i + " ," + j),
                     Percent = c.Field("Percent")
                                        

                 };

Split the String values with a special character in MS Flow to convert this into Array

 Many times we have a requirement to prepare the Mailing address for some of the documents, suppose there are Address Line1, Address Line2, ...