Tuesday, 26 April 2016

Hide Progress Bar or execute code after Response.End() Response.Flush()

Many times it may asked by customer to show Progress Bar while generating reports and export them in PDF/Excel or any other format.

You can not perform any operation on code behind after just Postback if you are calling below statements just to extract the data in files.

            Response.Clear();
            Response.ClearHeaders();
            Response.AppendHeader("content-type", "application/pdf");
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + "Activity.pdf");
            Response.BinaryWrite(result);
            Response.Flush();
            Response.End();

// Hide Progress Bar
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "unload", "javascript:HideProgress()", true);



Above script statement will not affect the loading bar as Response.End() Forcing Web server to stop processing the script and return the current result.

Below is the solution for that.

1. Created Below JS methods to show/hide the Progress Bar

function ShowProgress() {
    setTimeout(function () {
        var modal = $('<div />');
        modal.addClass("modal");
        $('body').append(modal);
        var loading = $(".loading");
        loading.show();
        var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
        var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
        loading.css({ top: top, left: left });
    }, 200);
}

function HideProgress() {

    setTimeout(function () {
        var loading = $(".loading");
        if (loading != null && loading != 'undefined')
            loading.hide();
    }, 1000);
    setTimeout(function () {
        var modal = $(".modal");
        if (modal != null && modal != 'undefined')
            modal.hide();
    }, 1000);


}

2. Call the JS method namely ShowProgress() wherever you want progress bar to come across like onclick on the button/Anker tag etc..

  <asp:LinkButton runat="server" ID="printSelected" OnClick="printSelected_Click" OnClientClick="form1.target='_self'; ShowProgress();" ToolTip="Print">
                        Print

                    </asp:LinkButton>


On Code behind .cs file

   protected void printSelected_Click(object sender, EventArgs e)
        {
      WriteFile();

        }

 private void WriteFile()
        {
            string sFileName = System.IO.Path.GetRandomFileName();
            string sGenName = "Friendly.txt";

           
            using (System.IO.StreamWriter SW = new System.IO.StreamWriter(
                   Server.MapPath("~/Activities/" + sFileName + ".txt")))
            {
                SW.WriteLine("test data");
                SW.Close();
            }

            System.IO.FileStream fs = null;
            fs = System.IO.File.Open(Server.MapPath("~/Activities/" +
                     sFileName + ".txt"), System.IO.FileMode.Open);
            byte[] btFile = new byte[fs.Length];
            fs.Read(btFile, 0, Convert.ToInt32(fs.Length));
            fs.Close();
          //  ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "unload", "javascript:HideProgress()", true);
            Response.AddHeader("Content-disposition", "attachment; filename=" +
                               sGenName);
            Response.ContentType = "application/octet-stream";
            Response.BinaryWrite(btFile);
            Response.End();
            Response.Flush();
          

        }

3. Put below script block anywhere in the script block: Which is hiding the Progress bar before the unload of the document.

$(window).bind('beforeunload', function () { HideProgress(); });




That's all using which you can implement progress bar.

Cheers!

 

Wednesday, 2 March 2016

How to get All Dirty Fields in a Form Using Java Script In MS CRM 2011

Today i got a requirement where i need to get all fields which have been modified by the user.
Also there is additional requirement to set their submit-mode to Never.

Sharing you XRM Script for the same.

function MakeFieldUnDirty() {
    var attributes = Xrm.Page.data.entity.attributes.get();
    for (var i in attributes) {
        var attribute = attributes[i];
        if (attribute.getIsDirty())
            attribute.setSubmitMode("never")
    }
}

------------------------------------------------

Making fields read-only is a great way to restrict change or to make sure input is valid. However, all read-only fields are not submitted by default onSave event.
This is not desirable if you are automatically populating fields from user input on another field(s) and those fields cannot be changed by user. Those auto-populated fields will never be saved.
To make sure the fields are saved, we can call javascript function setSubmitMode.
Xrm.Page.getAttribute("<field name>").setSubmitMode("<submit value>");
Submit values available are:
  • always
  • never
  • dirty

Tuesday, 23 February 2016

Opening up the HTML Web Resource from a Javascript

Hi All,

many times we are customizing CRM where we need to create a HTML web resource for some special UI/requirement and need to open using a modal popup.

Now here I am going to show, how can we open HTML Web Resource from a Javascript Function instead (triggered by the click of the Ribbon Button).


This function uses the Xrm.Utility.openWebResource() method introduced in Roll-Up 8  of CRM 2011.


The Function call allows you to specify the web resource URL, and the size of the pop-up window.

Xrm.Utility.openWebResource("new_webResource.htm?typename=account&userlcid=1033", null, 300, 300);


Some extra knowledge with this :)



Cheers,
Jitendra Sahu

Friday, 30 October 2015

New features listed in Microsoft Dynamics CRM 2016

Microsoft released the preview guide for the new release this month, so we thought we would give our readers a taste of some of the upcoming features that we are most excited about! 

First off, let’s break down some of the basics. Microsoft Dynamics CRM 2016 Online is set to be released in December of this year. The name of the game with CRM 2016 is customer service. Microsoft is really focusing on helping companies “deliver customer experiences that are personalized, proactive and predictive.” The 2016 update will include Dynamics CRM; Parature, from Microsoft; Dynamics Marketing; and Microsoft Social Engagement.
Microsoft is striving to drive home four major themes: Productivity, Intelligence, Mobility and Unified Service. They are also investing heavily in Dynamics Marketing and Microsoft Social Engagement, which bodes well for all areas. Let’s dive into some of the features we are the most excited about overall! 

Online: Guided User Experience


Below are some of the enhancements that are in store for Dynamics CRM 2016:
  • New Excel Templates: Dynamics CRM 2015 allows you to conduct analysis in Excel directly within the platform, view sales data in familiar Excel templates, get analysis and insights directly into the sales process and efficiently manage sales forecasts, eliminating time and effort required to switch between applications. In addition, it allows you to export and analyze Excel data from your mobile device with Dynamics CRM 2016 apps for tablets and smartphones.
  • CRM App for Outlook: Getting key sales capabilities within the Outlook desktop and mobile browser has become more streamline. You will be able to open documents using different applications like Word or PowerPoint on various devices like iPads and smartphones. Now, you have the option to get contextual information from Dynamics CRM delivered right in your mailbox for quick and easy review.
  • Improved Outlook Experience: Harness the power of O365 Groups, in 2016, you can get easy access to Excel templates and create personalized sales documents in Word. Easily track emails and add contacts with the touch of a button from within an email. You can also generate new records to track emails through a web browser on a PC, or a mobile browser on a smart phone.
  • Enhanced Mobile Experience: Full offline capabilities are now available for your sales and service professionals on smart phones and tablets across all major operating systems. Quickly complete sales related activities while on the go and streamline important deals, accounts and activities with verbal instruction to Cortana.
  • SMS Marketing: Build your sales pipeline and chart out your marketing activities, from planning, and execution to measuring your marketing performance. You’ll be able to create powerful SMS campaigns and integrate them with your multi-channel campaigns. Easily configure inbound SMS campaigns, send outgoing promotional SMS messages and maintain a database of your marketing contacts.
  • Cloud Enhancements: Discover information that’s most relevant and interesting to you. Track documents wherever they are stored (via OneDrive or O365). You will also be able to get a list of trending documents from Delve inside CRM. View a consolidated set of documents across SharePoint, OneDrive for Business and O365 groups. Discover information that can help you with your current opportunities or accounts.
  • Cortana Integration: Dynamics CRM 2016 embeds various sales activities, accounts and opportunities into Cortana to provide the most relevant information to your sales team. Get access to advanced data management and advanced analytics capabilities and improve your customer service with the Cortana Analytics Suite.
  •  
    Sales: Cortana Integration
  • Improved Document Generation: Build personalized sales documents with Document Generation using pre-defined Word and Excel templates with one click. Ultimately, saving you time in building documents. Automatically have CRM data from account summaries, quotes and invoices, and product sheets extracted.
  • Enriched Data and Analytics: Turn business critical data into intelligent action and achieve elevated business transformation. Obtain intelligent product suggestions for cross-selling and recommend solutions to solve customer service issues. You will also be able to gain insights into your business and efficiently predict customer needs with Azure Machine learning.
  • Microsoft Social Engagement: Evaluate and drive social engagement within Dynamics CRM 2016. Easily pinpoint leads from social media and understand social buzz around a product. You’ll instantly gain access to powerful social tools and connect with customers, partners and prospects on various social media sites. Obtain social insights about your brand and get a true understanding of your position in the industry.
    Social: Social Listening and Social Analytics

Superior Customer Engagement
Superior customer engagement is the principal goal of Dynamics CRM 2016. By delivering end-to-end customer solutions across field service, assisted service and self-service, Dynamics CRM 2016 drives its entire focus on delivering remarkable customer experiences. Reap benefits of productivity and intelligence through a single platform to personalize experiences and have proactive and contextual interactions with customers to identify and meet their distinct needs.

Saturday, 17 October 2015

Learn Microsoft Dynamics CRM Step By Step


Table of Contents