Search This Blog

Showing posts with label CRM Javascript. Show all posts
Showing posts with label CRM Javascript. Show all posts

Wednesday, July 12, 2017

Dynamics CRM DateTime format filter in web API

Dynamics CRM DateTime format filter in web API:
function getODataUTCDateFilter(date) {
   var monthString;
   var rawMonth = (date.getUTCMonth() + 1).toString();
   if (rawMonth.length == 1) {
       monthString = "0" + rawMonth;
   }
   else { monthString = rawMonth; }
   var dateString;
   var rawDate = date.getUTCDate().toString();
   if (rawDate.length == 1) {
       dateString = "0" + rawDate;
   }
   else { dateString = rawDate; }
   var hourString = date.getUTCHours().toString();
   if (hourString.length == 1)
       hourString = "0" + hourString;
   var minuteString = date.getUTCMinutes().toString();
   if (minuteString.length == 1)
       minuteString = "0" + minuteString;
   var secondString = date.getUTCSeconds().toString();
   if (secondString.length == 1)
       secondString = "0" + secondString;
   var DateFilter = "datetime'";
   DateFilter += date.getUTCFullYear() + "-";
   DateFilter += monthString + "-";
   DateFilter += dateString;
   DateFilter += "T" + hourString + ":";
   DateFilter += minuteString + ":";
   DateFilter += secondString + "Z'";
   return DateFilter;
}

"IN" operation in fetch XML on Lookup control AddPresearch

"IN" operation in fetch XML on Lookup control AddPresearch


In the account lookup filter two(n of account) account name:
<filter type='and'>

<condition attribute='name' operator='in'>
<value>Test</value>
<value>ABCD</value>
</condition>

</filter>

Enable and Disable controls inside a tab


 Enable / Disable a Section

function sectiondisable(sectionname, disablestatus) {
    var ctrlName = Xrm.Page.ui.controls.get();
    for (var i in ctrlName) {
        var ctrl = ctrlName[i];
        if (ctrl.getParent() == null)
            continue;
        var ctrlSection = ctrl.getParent().getName();
        if (ctrlSection == sectionname) {
            ctrl.setDisabled(disablestatus);
        }
    }
}


 Enable / Disable a Tab
function tabdisable(tabname, disablestatus) {
    var tab = Xrm.Page.ui.tabs.get(tabname);
    if (tab == null)
        return;
    else {
        var tabsections = tab.sections.get();
        for (var i in tabsections) {
            var secname = tabsections[i].getName();
            sectiondisable(secname, disablestatus);
        }
    }
}

Friday, September 30, 2016

Get Object type code using javascript

Get Object type code using javascript

Xrm.Page.context.getQueryStringParameters().etc

Friday, July 22, 2016

Get parameter value from QueryString in CRM

function ParseQueryString(query) {
    var result = {};

    if (typeof query == "undefined" || query == null) {
        return result;
    }

    var queryparts = query.split("&");
    for (var i = 0; i < queryparts.length; i++) {
        var params = queryparts[i].split("=");
        result[params[0]] = params.length > 1 ? params[1] : null;
    }
    return result;
}

var passedparams = ParseQueryString(GetGlobalContext().getQueryStringParameters()["Data"]);

Open HTML page when button click in CRM

In the web resource there is a html file new_IntialExemption.html.

//If you need to pass any parameters use following code instead:
var webresourceurl = "/webresources/new_IntialExemption?Data=" + encodeURIComponent(addParams);


//First parameter - prepared url of dialog
//Second parameter - control from which you open dialog
//Third and Fourth - width and height
var dialogwindow = new Mscrm.CrmDialog(Mscrm.CrmUri.create(webresourceurl), window, 350, 200);

//use setCallbackReference method to call some handler once dialog is closed
//to result variable would be returned result of dialog call
dialogwindow.setCallbackReference(function (result) {
    callAvaEmailCertCapture()
});

//call this method to show dialog
dialogwindow.show();

function callAvaEmailCertCapture() {

}

Wednesday, March 16, 2016

XRM Methods in Date controls,Notification and Enity

Notification
Xrm.Page.getControl(fieldName).setNotification(message)
Xrm.Page.getControl(fieldName).clearNotification()
Date
Xrm.Page.getControl(arg).setShowTime(bool)
Gets a string for the value of the primary attribute of the entity.
Xrm.Page.data.entity.getPrimaryAttributeValue()

Monday, March 14, 2016

Which one fire first Java-script or Business Rule Running Order

JavaScript trigger and then trigger business rule.

Running Order

It’s possible you could have JavaScript and numerous business rules all running against one field, so the order things run can have a dramatic effect on the outcome.


  1. Any system scripts are applied first.
  2. Any logic in custom form scripts is applied.
  3. Logic in business rules is applied.When there are multiple business rules, they are applied in the  order they were activated, from oldest to newest. 

Accessing Parent form control in CRM

Access account form control from address form
parent.window.opener.Xrm.Page.getAttribute('new_nonupdatable').getValue()

window.opener.Xrm.Page.getAttribute('new_nonupdatable').getValue()

Wednesday, November 25, 2015

Create button in CRM form using javascript with field

Create button in CRM form using javascript with field

If you have any doubt in the post please post comments. I will try to solve your problem.

Step 1:-Add a new attribute of type single line text in CRM form or you may use existing one.

Step 2: Add the fallowing code to your crm java script web resource. And call this function in the form onload.

function MakeButton() { 
        var atrname ="YOUR ATTRIBUTE SCHEMA NAME";// "new_stringtest";
        if (document.getElementById(atrname ) != null) {
        var fieldId = "field" + atrname ;
        if (document.getElementById(fieldId ) == null) {
            var elementId = document.getElementById(atrname + "_d");
            var div = document.createElement("div");
            div.style.width = "100px";
            div.style.textAlign = "right";
            div.style.display = "inline";
            elementId .appendChild(div, elementId );
            div.innerHTML = '<button id="' + fieldId + '"  type="button" style="margin-left: 3px; width: 100%;" >CRM Form Button</button>';
            document.getElementById(atrname).style.width = "0%";
            document.getElementById(fieldId ).onclick = function () { YourOnClickFunction(); };
        }
    }
}

function YourOnClickFunction(){
alert("Hi");

}

Disable autosave particular form in javascript CRM

Disable autosave particular form in javascript CRM

If you have any doubt in the post please post comments. I will try to solve your problem.

  1. Write following JavaScript code in your entity JavaScript file.

                  function preventAutoSave(econtext) {
                        var eventArgs = econtext.getEventArgs();
                       if (eventArgs.getSaveMode() == 70) {
                              eventArgs.preventDefault();
                        }
                  }
  1. In the Form Properties window, in the Event Handlers section, set Event to OnSave.
  2. Click on Add  and choose the above code written JavaScript resource file
  3. In the Handler Properties window, set Library to the web resource you added in the previous step.
  4. Type ‘preventAutoSave’ in the Function field. This is case sensitive. Do not include quotation marks.
  5. Make sure that Enabled is checked.
  6. Check Pass execution context as first parameter.
  7. Click OK to close the Handler Properties dialog.
  8. The Handler Properties dialog should look like this.
  9. AutoSave2
    After you apply this script to the OnSave event, when people edit a record using this form the message unsaved changes will appear in the bottom right corner of the form just as it would if auto-save was not disabled. But this message will not go away until people click the Savebutton next to it.