Read Option set Text/Value at one go CRM 2013

Often we have requirement to read option set Text/Value quickly, I wrote a script to quickly read all option sets on a form

Go to Google chrome console(Press F12 in Chrome), select the option Console as per screen, Note that contentIframe0 is selected  :

image

and run following script on your form :

var attributes = Xrm.Page.data.entity.attributes.get();

var optionSetAttributes = ”;
var optionSetValues = ”;
Xrm.Page.ui.controls.forEach(function (control, index) {
    if (control.getControlType() == ‘optionset’) {
        optionSetValues = ”;
        var controlName = “#” + control.getName() + “_i”;
        optionSetValues += control.getName() + ” option set values below: \n\n”;
        $(controlName).find(‘option’).first().nextAll().each
        (function () {
            optionSetValues += ‘<div>’ + ‘Value: ‘ + $(this).attr(‘value’) + ‘,Title: ‘ + $(this).attr(‘title’) + ‘</div>’;
        }
        );
    }
    optionSetAttributes += ‘<div>’ + optionSetValues + ‘</div>’;
});

var htmlString = ‘<div style= “overflow:always”>’ + optionSetAttributes + ‘</div>’;
$(“#processControlCollapsibleArea”).after(htmlString);

var w = window.open(“Surprise”, “#”);
var d = w.document.open();
d.write(htmlString);
d.close();

You will get following new page:

image

Just do Ctrl+ C and you are done!

Hope it helps!

Advertisements

Get Hidden field names on form: Dynamics CRM 2011/2013

This script will alert all hidden field names on form:

var attributes = Xrm.Page.data.entity.attributes.get();

var hiddenAttributes = ”;

Xrm.Page.ui.controls.forEach(function (control, index)

{ if (control.getVisible() == false) { hiddenAttributes += control.getName() + ‘,’;

   }

} );

alert(hiddenAttributes);

Change color for text fields : Dynamics CRM 2013

Sometimes we get requirement to change the forecolor for some fields in Dynamics CRM 2013 in order to highlight them in different color. So we implemented following script:

You can add the scripts on-load or based on some condition.

For changing color during field is non-selected:

//Setting red color

$(‘#fieldname’).find(‘div[class=”ms-crm-Inline-Value”]’).css(‘color’,color);

Now Field looks like this:

image

In order to change color during field is typed:

//Setting color blue during typing of field

$(‘#fieldname_i’).css(‘color’, color);

UI will look like below now:

image

Note: This is unsupported script and may break in future if Microsoft changes something.

Hope it helps!


Check this out

Trying to Learn Dynamics CRM: Download!

Learn Dynamics CRM App on Google Play store