Search This Blog

Thursday, November 7, 2019

Refresh Form/Record using javascript in dynamics 365 v9 Unified Interface

setTimeout(function () {          
        top.callN = null;
        Xrm.Utility.openEntityForm(formContext.data.entity.getEntityName(), formContext.data.entity.getId());
      }, 2000);

Wednesday, October 16, 2019

Get and Set Value from Custom Ribbon Button using javascript Dynamics 365 V9

function Set(PrimaryControl)
{
    var formContext = PrimaryControl;
        formContext.getAttribute("schedule").setValue(true);
    formContext.data.entity.save();
}

Tuesday, August 6, 2019

Deserialize Json Array Object to DataTable

Use Below Code

protected void GetCustomerType()
        {
            String serverurl = "API URL";
            Uri myUri = new Uri(serverurl);
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(myUri);
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method = "GET";

            HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            Stream dataStream = httpResponse.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            string sResponse = reader.ReadToEnd();

            DataTable dt = JsonStringToDataTable(sResponse);
            foreach (DataRow dr in dt.Rows)
            {
                String name = dr[""].ToString();
                String telephone = dr[""].ToString();
                String email = dr[""].ToString();
            }

                    }
        public DataTable JsonStringToDataTable(string jsonString)
        {
            DataTable dt = new DataTable();
            string[] jsonStringArray = Regex.Split(jsonString.Replace("[", "").Replace("]", ""), "},{");
            List<string> ColumnsName = new List<string>();
            foreach (string jSA in jsonStringArray)
            {
                string[] jsonStringData = Regex.Split(jSA.Replace("{", "").Replace("}", ""), ",");
                foreach (string ColumnsNameData in jsonStringData)
                {
                    try
                    {
                        int idx = ColumnsNameData.IndexOf(":");
                        string ColumnsNameString = ColumnsNameData.Substring(0, idx - 1).Replace("\"", "");
                        if (!ColumnsName.Contains(ColumnsNameString))
                        {
                            ColumnsName.Add(ColumnsNameString);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(string.Format("Error Parsing Column Name : {0}", ColumnsNameData));
                    }
                }
                break;
            }
            foreach (string AddColumnName in ColumnsName)
            {
                dt.Columns.Add(AddColumnName);
            }
            foreach (string jSA in jsonStringArray)
            {
                string[] RowData = Regex.Split(jSA.Replace("{", "").Replace("}", ""), ",");
                DataRow nr = dt.NewRow();
                foreach (string rowData in RowData)
                {
                    try
                    {
                        int idx = rowData.IndexOf(":");
                        string RowColumns = rowData.Substring(0, idx - 1).Replace("\"", "");
                        string RowDataString = rowData.Substring(idx + 1).Replace("\"", "");
                        nr[RowColumns] = RowDataString;
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }
                }
                dt.Rows.Add(nr);
            }
            return dt;
        }

Tuesday, May 21, 2019

Get Sum/Aggregate from Related entity using c# in Dynamics CRM

public int GetTotal()
{
FetchExpression f1 = new FetchExpression("<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true' aggregate='true' >" +
                    "    <entity name='account' >" +
                    "        <filter type='and' >" +
                    "            <condition attribute='statuscode' operator='in' >" +
                    "                <value>" +
                    "                    1" +
                    "                </value>" +
                    "                <value>" +
                    "                    175650000" +
                    "                </value>" +
                    "            </condition>" +
                    "        </filter>" +
                    "        <link-entity name='batch' from='batchid' to='batchid' visible='false' link-type='outer' alias='bc' >" +
                    "            <attribute name='credithour' aggregate='sum' alias='totalcredithours' />" +
                    "        </link-entity>" +
                    "    </entity>" +
                    "</fetch>");

EntityCollection AccountCollection = service.RetrieveMultiple(f1);
                int total = 0;
                if (AccountCollection != null)
                {
                    AccountCount = AccountCollection.Entities.Count;
                    if (AccountCount > 0)
                    {
                        foreach (var entity in AccountCollection.Entities)
                        {
                            if (entity.Attributes.Contains("totalcredithours"))
                            {
                                total = Convert.ToInt16(((AliasedValue)entity.Attributes["totalcredithours"]).Value);
                            }
                            return total;
                        }
                    }
                }
}


Monday, May 20, 2019

Insert in List Item in Shairpoint online using c#

 protected void InsertItem()
        {
            try
            {
                SecureString Password = new SecureString();
                Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

                foreach (char c in "password")
                {
                    Password.AppendChar(c);
                }
                    ClientContext clientcontext = new ClientContext(url);//"https://orgname.sharepoint.com/sites/MainListSite"
                    clientcontext.Credentials = new SharePointOnlineCredentials(username, Password);

                    List olist = clientcontext.Web.Lists.GetByTitle("FirstMainList");
                    ListItemCreationInformation listiteminfor = new ListItemCreationInformation();
                    Microsoft.SharePoint.Client.ListItem olistitem = olist.AddItem(listiteminfor);

                    olistitem["Title"] = "1";
              
                    olistitem.Update();
                    clientcontext.ExecuteQuery();

            }
            catch(Exception ex)
            {
                Label1.Text = ex.Message;
            }
        }

Retrieve List Items form Shairpoint Online in c#

protected void GetListItem()
        {
            try
            {
                SecureString Password = new SecureString();
                Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

                foreach (char c in "password")
                {
                    Password.AppendChar(c);
                }
                using (ClientContext context = new ClientContext(url))//https://orgname.sharepoint.com/sites/MainListSite"
                {
                    context.Credentials = new SharePointOnlineCredentials(username, Password);

                    List list = context.Web.Lists.GetByTitle("FirstMainList");//list name
                    context.Load(list);
                    context.ExecuteQuery();
                    Microsoft.SharePoint.Client.View view = list.Views.GetByTitle("All Items");//view name

                    context.Load(view);
                    context.ExecuteQuery();
                    CamlQuery query = new CamlQuery();
                    query.ViewXml = view.ViewQuery;

                    Microsoft.SharePoint.Client.ListItemCollection items = list.GetItems(query);
                    context.Load(items);
                    context.ExecuteQuery();
                    //Console.WriteLine("Total Count: " + items.Count);

                    foreach (Microsoft.SharePoint.Client.ListItem itm in items)
                    {
                        Label1.Text = itm["Title"].ToString() + itm["Mobile"].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                Label1.Text = "Exception " + ex.Message;
            }
        }

Monday, March 11, 2019

Encrypt and Decrypt Connection String using CMD


Encrypt:


cd C:\Windows\Microsoft.Net\Framework\v4.0.30319
ASPNET_REGIIS -pef "appSettings" "folder path where web.config"


DeCrypt:

cd C:\Windows\Microsoft.Net\Framework\v4.0.30319
ASPNET_REGIIS -pdf "appSettings" "folder path where web.config"





Wednesday, March 6, 2019

SQL Query to Get size of Table

EXEC sp_spaceused N'User.ContactInfo';

SQL Query to Get Table Index fragmentation

Query:

SELECT * FROM sys.dm_db_index_physical_stats(dbid, table_objectid, NULL, NULL , 'LIMITED')
ORDER BY avg_fragmentation_in_percent DESC

SQL Query to Get Database ID and Table Object ID in Dynamics CRM

Get DB Id:

SELECT DB_ID(N'dbname') AS [Database ID];


Get Table Object ID:

Use dbname
SELECT name, object_id 
FROM sys.tables 
WHERE name = 'IncidentBase'; 
GO

Friday, March 1, 2019

Get and Set Dynamics CRM Attribute Values in c#

Set OptionsetValue:

entity.Attributes.Add("attributename", new OptionSetValue(1));

Set Money Attribute:

Decimal  creditlimit=0;

entity.Attributes.Add("attributename", new Money(creditlimit));

Set Lookup:

EntityReference _event = new EntityReference();
                        _event.Id = guid;
                        _event.LogicalName = "entityname";
                        _event.Name = name;
                        entity.Attributes["attributename"] = _event;

DateTime:

entity.Attributes.Add("attributename", Start_date);

Get Alias Attribute Values in Dynamics CRM using c#

Single Line of Text:

String name = ((AliasedValue)entity.Attributes["name"]).Value.ToString();


OptionsetValue:

String optionsetvalue = ((AliasedValue)entity.Attributes["attributename"]).Value.ToString();


OptionsetText:

String optionsettext = entity.FormattedValues["attributename"].ToString();


Lookup:

String name = ((EntityReference)((AliasedValue)entity.Attributes["attributename"]).Value).Name;
String id= ((EntityReference)((AliasedValue)entity.Attributes["attributename"]).Value).Id.ToString();


Currency:
 Fetchxml Query:

<entity name='account'>
                <attribute name='name' />
                <attribute name='accountid' />
                <order attribute='name' descending='false' />
                <filter type='and'>
                  <condition attribute='statecode' operator='eq' value='0' />
                </filter>
                <link-entity name='amountentity' from='amountentityid' to='amountentity' visible='false' link-type='outer' alias='amount_entity'>
                  <attribute name='totalamount' />
                </link-entity>
              </entity>

Decimal amount = ((Money)(((AliasedValue)student.Attributes["amount_entity.totalamount"])).Value).Value;


Whole Number:

int Totalnumber = Convert.ToInt16(((AliasedValue)entity.Attributes["totalcredithours"]).Value);