Wednesday, 8 March 2017

Entity Statecodes and Statuscodes

AIM: To list down the statecodes and statuscodes of the commonly used entities. 

Recently I was trying to change the statecode of email and had a tough time finding the valid status' and status reasons.

Below is the list of the entity statecodes and statuscodes. Use Ctrl+F to find the entity by display name or schema name.


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
100003 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

Friday, 6 May 2016

Export HTML Table to PDF in ASP.NET

 There are many ways we can export HTML Table to PDF document. Here I’ll explain the easiest way to export HTML Table to PDF.  
WebClient class provide the feature to download the HTML string from current URL. First we need to make sure that how we can extract HTML Table from entire source code and how we can get content from that HTML table.  <table> tag contains <tr> and <td> tags but it may have style properties. So first we have to avoid these style properties and after we can get required content from table.
   Here we have to format HTML tags for avoid style properties




Sample code:
    const string msgFormat = "table[{0}], tr[{1}], td[{2}], a: {3}, b: {4}";   
    const string table_pattern = "<table.*?>(.*?)</table>";
    const string tr_pattern = "<tr.*?>(.*?)</tr>";
    const string td_pattern = "<td.*?>(.*?)</td>";
    const string a_pattern = "<a href=\"(.*?)\"></a>";
    const string b_pattern = "<b>(.*?)</b>";

          After through looping we can find <tr> and <td> elements. Then we can get content within <td></td> tags by using this method.
private static List<string> GetContents(string input, string pattern)
    {
        MatchCollection matches = Regex.Matches(input, pattern, RegexOptions.Singleline);
        List<string> contents = new List<string>();
        foreach (Match match in matches)
        contents.Add(match.Value);
        return contents;
    }

Designer source code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"
    EnableEventValidation="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>HTML to PDF</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="width:500px; height:200px">
            <tr>
                <td> Name </td>
                <td> Age  </td>
                <td> Sex  </td>
            </tr>
            <tr>
                <td> Sachin </td>
                <td> 25 </td>
                <td> Male </td>
            </tr>
            <tr>
                <td> Saran </td>
                <td> 24 </td>
                <td> Male </td>
            </tr>
            <tr>
                <td> Priya </td>
                <td> 24 </td>
                <td> Female </td>
            </tr>
        </table>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
    </div>
    </form>
</body>
</html>

C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Adapters;
using System.Collections;
using System.Text.RegularExpressions;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using System.Net;
using iTextSharp.text.html.simpleparser;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {    }
     const string msgFormat = "table[{0}], tr[{1}], td[{2}], a: {3}, b: {4}";   
    const string table_pattern = "<table.*?>(.*?)</table>";
    const string tr_pattern = "<tr.*?>(.*?)</tr>";
    const string td_pattern = "<td.*?>(.*?)</td>";
    const string a_pattern = "<a href=\"(.*?)\"></a>";
    const string b_pattern = "<b>(.*?)</b>";

    private static List<string> GetContents(string input, string pattern)
    {
        MatchCollection matches = Regex.Matches(input, pattern, RegexOptions.Singleline);
        List<string> contents = new List<string>();
        foreach (Match match in matches)
        contents.Add(match.Value);
        return contents;
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {       
        WebClient wc = new WebClient();
        string url = Request.Url.AbsoluteUri;
        string fileContent = wc.DownloadString(url); 
        List<string> tableContents = GetContents(fileContent, table_pattern);
        string HTMLString = String.Join(" ", tableContents.ToArray());   
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);             
        pdfDoc.Open();
        pdfDoc.Add(new Paragraph("Welcome to dotnetfox"));
        List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StringReader(HTMLString), null);
        for (int k = 0; k < htmlarraylist.Count; k++)
        {
            pdfDoc.Add((IElement)htmlarraylist[k]);
        } 
        pdfDoc.Close();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition""attachment;" +
                                       "filename=sample.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Write(pdfDoc);
        Response.End();       
    }   
}

Monday, 7 December 2015

CRM 2013 Role Based optionset Values





if (!XrmServiceToolkit.Soap.IsCurrentUserRole("System Administrator")) {

        var xrmPage = Xrm.Page;
        var pickListField = xrmPage.getAttribute("new_passorfail");
        var StatusValue = xrmPage.getAttribute("new_passorfail").getValue();
        var options = pickListField.getOptions();
        for (var i = 0; i < options.length; i++) {
            if (options[i].value != StatusValue) {
                Xrm.Page.getControl("new_passorfail").removeOption(options[i].value);
            }
        }
        //save all options
        if (!window.wsOptions) {
            window.wsOptions = {};
            wsOptions.pass = pickListField.getOption(920170000);
            wsOptions.fail = pickListField.getOption(920170001);
            wsOptions.waiting = pickListField.getOption(920170002);
            wsOptions.retest = pickListField.getOption(920170003);
            wsOptions.invalid = pickListField.getOption(920170004);
            wsOptions.spec = pickListField.getOption(920170005);
            wsOptions.fixed = pickListField.getOption(920170006);
        }

        if (XrmServiceToolkit.Soap.IsCurrentUserRole("Developer")) {

            if (wsOptions.spec.value != StatusValue)
                Xrm.Page.getControl("new_passorfail").addOption(wsOptions.spec);
            if (wsOptions.invalid.value != StatusValue)
                Xrm.Page.getControl("new_passorfail").addOption(wsOptions.invalid);
            if (wsOptions.retest.value != StatusValue)
                Xrm.Page.getControl("new_passorfail").addOption(wsOptions.retest);
            if (wsOptions.fixed.value != StatusValue)
                Xrm.Page.getControl("new_passorfail").addOption(wsOptions.fixed);
        }
        if (XrmServiceToolkit.Soap.IsCurrentUserRole("Tester")) {
            if (wsOptions.pass.value != StatusValue)
                Xrm.Page.getControl("new_passorfail").addOption(wsOptions.pass);
            if (wsOptions.fail.value != StatusValue)
                Xrm.Page.getControl("new_passorfail").addOption(wsOptions.fail);
            if (wsOptions.waiting.value != StatusValue)
                Xrm.Page.getControl("new_passorfail").addOption(wsOptions.waiting);
         
            }
        }
    }

CRM 2013 Bulk Edit Form - to enable Scripts



Similar to MSCRM 4, events won't fire by default in CRM 2013.  Also, any field with an onchange event will be rendered disabled!  There is a nasty way to go about it enabling these fields or allowing your scripts to execute.


Export the entity you wish to enable scripted bulk edits for in an unmanaged solution.  Un-zip the package and open up customizations.xml.


To allow an event, follow the below xpath which will take you to the events for a form.  If you have multiple forms, you may repeat for each form (TBD:  not sure if these appear under systemform or not).  If you're enabling for multiple entities, you may repeat for each entity.


\\ImportExportXml\Entities\Entity[@name='new_entityname']\FormXml\forms[@type=’main’]\systemform\form\events\event[@name=’onload’]



This xpath takes us to the onload event for the main form of the new_entityname entity.  To this node, we need to add the BehaviorInBulkEditForm attribute.


<event name="onload" application="false" active="true" BehaviorInBulkEditForm="Enabled">


Enabled - If this is an event related to a field (onchange), then the field will be enabled.  The script will run.

EnabledButNoRender - If this is an event related to a field (onchange), then the field will be enabled.  However, the script will not run.
Disabled - (default) If this is an event related to a field, then that field will be disabled.  The script will not run.

Thursday, 16 October 2014

Create your own Hot spot in laptop


                   
                         Open the notepad and type these below lines save as .bat extension and run as administrator

netsh wlan set hostednetwork mode=allow ssid=username key=password

netsh wlan start hostednetwork
netsh wlan show hostednetwork





To stop the hot shot

               
                           Open the notepad and type these below lines save as .bat extension and run as administrator

netsh wlan stop hostednetwork

netsh wlan show hostednetwork



To delete the hotspot


                              Open the notepad and type these below lines save as .bat extension and run as administrator


netsh wlan stop hostednetwork

netsh wlan set hostednetwork mode=disallow
netsh wlan show hostednetwork

Friday, 23 May 2014

Downloading Large files from Windows Azure

 





//Retrieve filenname from DB (based on fileid (Guid))
// *SNIP*
string filename = "Dinesh.txt";


if (HttpContext.Current.Request.UserAgent != null &&
HttpContext.Current.Request.UserAgent.ToUpper().Contains("MSIE"))
    filename = HttpUtility.UrlEncode(filename,
 System.Text.Encoding.UTF8).Replace("+", " ");

context.Response.Charset = "UTF-8";

context.Response.Buffer = false;
context.Response.AddHeader("Content-Disposition",
 "attachment; filename=\"" + filename + "\"");
context.Response.AddHeader("Content-Length", "100122334");
//Set the length the file
context.Response.ContentType = "application/octet-stream";
context.Response.Flush();

//Use the Azure API to stream the blob to the user instantly.
// *SNIP*
fileBlob.DownloadToStream(context.Response.OutputStream);

Tuesday, 25 June 2013

How to Get or Set AppSettings in web.config file using asp.net.(CodeBehind)




Now I will explain how to write appsettings in web.config file and how to read appsettings from web.config file using asp.net.


To add appsettings first create new website open web.config file and search for “appSettings” and add new item in appSettings section.The section is like this.

<appSettings>
<add key="yourappsettingsstringName" value=" yourappsettingsvalue" />
</appSettings>

The main purpose used for appsettings is for declaring the connection string.because if we have a too many pages in application then it will not require to write connection string on every page.However we can define any key which are used in many pages.

Example of declaring appSettings in web.config file like this.

<appSettings>
<add key="dbconnectionstring" value="Data Source=DineshIyngaran;Initial Catalog=MysampleDB; Integrated Security=true"/>
</appSettings>

The good advantage of writing the appsettings in web config is we can manage it easily.means if we want to change its value then we can change it only in appsetting.we dont need to write and change it in every pages.This is the biggest advantage of it.

Lets take an Example.and test it.


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Read or Write appsetting values from web.config file in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblText" runat="server"/>
</div>
</form>
</body>
</html>

After that add following namespace in codebehind file

using System;
using System.Configuration;

 The namespace using System.Configuration; is used to get configuration section details from web.config file.

After add namespaces write the following code in code behind

protected void Page_Load(object sender, EventArgs e)
{
//Get appsettings string value from web.config file
string strcon = System.Configuration.ConfigurationManager.AppSettings["dbconnectionstring"];
//Bind appsettings string value to label
lblText.Text = strcon;


//set appsettings
 ConfigurationManager.AppSettings.Set("yourappsettingsstringName", "yourappsettingsvalue");
}



Hide New... button on lookup controls in model-driven apps

  The 'New ...' button is shown upon opening the lookup search dialog whenever the logged in user has at least user create privileg...