Friday, March 20, 2015

Get/Set currency field values in JavaScript for Dynamics CRM

I noticed a scenario where currency field value on CRM forms were not accessible using Xrm.Page.getAttribute(“Currency field name”).getValue() and 
Xrm.Page.getAttribute(“Currency field name”).setValue(Value)
The resolution is in such cases you can access currency fields in below manner:
// To get currency field
Xrm.Page.data.entity.attributes.get(“Currency field name”).getValue();
// To set currency field
Xrm.Page.data.entity.attributes.get(“Currency field name”).setValue(Value);

JavaScript Dependency Checker for Dynamics CRM 2011/2013

JavaScript Dependency Checker for Dynamics CRM 2011/Dynamics CRM 2013 is utility for all CRM administrators, consultants who have to deal with JavaScript issues on CRM 2011/CRM 2013 and want a quick way to document scripts. It is also very useful during product upgrades. 

Thank you to all

Thank you to all who have been reading my blog articles and have commented and sent personal messages. 

I started again posting in the blog after a long break!!! 

It means a lot to me to know some of my content might be helping. 

Monday, November 3, 2014

DataGrid Export to Excel

//btnExporttoExcel
Response.Clear();
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();
Response.Charset = "";
string FileName = "MS EXCEL" + DateTime.Now + ".xls";
StringWriter strwritter = new StringWriter();
HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);
dgpayment.GridLines = GridLines.Both;
dgpayment.HeaderStyle.Font.Bold = true;
dgpayment.RenderControl(htmltextwrtter);
Response.Write(strwritter.ToString());
Response.End();

//another method

public override void VerifyRenderingInServerForm(Control control)
        {
            //
        }

Business Process stage field: Dynamics CRM 2013 Javascript

Enable/Disable Business Process stage field:
Xrm.Page.getControl(‘header_process_fieldname’).setDisabled(false);  //Enabled
Xrm.Page.getControl(‘header_process_fieldname’).setDisabled(true);  //Disabled
Show/Hide Business Process stage field:
Xrm.Page.getControl(‘header_process_fieldname’).setVisible(true);  //Show
Xrm.Page.getControl(‘header_process_fieldname’).setDisabled(false);  //Hide
Get Value/ Set Value Business Process stage field:
Xrm.Page.getControl(‘header_process_fieldname’).getAttribute().setValue(value);  //Set Value
Xrm.Page.getControl(‘header_process_fieldname’).getAttribute().getValue();  //Get Value
Set and Remove Notification on Business Process stage field:
Xrm.Page.getControl(‘header_process_fieldname’).setNotification(“Notificationmessage”);  //Set Notification message
Xrm.Page.getControl(‘header_process_fieldname’).clearNotification(); // Clear Notification message
Set Required levels on Business Process stage field:
(Xrm.Page.getControl(‘header_process_fieldname).getAttribute()).setRequiredLevel(‘required’); //Required level
(Xrm.Page.getControl(‘header_process_fieldname).getAttribute()).setRequiredLevel(‘none’); //none level
(Xrm.Page.getControl(‘header_process_fieldname).getAttribute()).setRequiredLevel(‘recommended’); //Recommended level

Note: I have noticed this code will work when current stage field in business process on form is visible on UI.

Get/Set currency field values in JavaScript for Dynamics CRM

We Cannot use the below code to retrieve the currency field value
Xrm.Page.getAttribute(“Currency field name”).getValue() and Xrm.Page.getAttribute(“Currency field name”).setValue(Value)

The resolution is in such cases you can access currency fields in below manner:
// To get currency field
Xrm.Page.data.entity.attributes.get(“Currency field name”).getValue();
// To set currency field

Xrm.Page.data.entity.attributes.get(“Currency field name”).setValue(Value);

Tuesday, October 28, 2014

Xrm.Utility.openEntityForm for Dynamics CRM 2013/2011

Open a new account record using JavaScript
Xrm.Utility.openEntityForm(“account”);

Open an existing account record JavaScript
Xrm.Utility.openEntityForm(“account”,”A85C0252-DF8B-E111-997C-00155D8A8410″);

Open a new account record with a specific form and setting default values JavaScript
var parameters = {};
parameters["formid"] = “b053a39a-041a-4356-acef-ddf00182762b”;
parameters["name"] = “Test”;
parameters["telephone1"] = “(425) 555-1234″;

Xrm.Utility.openEntityForm(“account”, null, parameters);

Open a new record with setting form values for regardingobjectid will not work. So, in that case, the Workaround? Here we go:

Open Form Script

//set the parameters to pass to the new form
var parameters = {};
var Regarding = Xrm.Page.getAttribute(“regardingobjectid”).getValue();
parameters["parameter_regardingid"] = Regarding[0].id;
parameters["parameter_regardingname"] = Regarding[0].name;
parameters["parameter_regardingtype"] = Regarding[0].entityType;
//Open the new form
Xrm.Utility.openEntityForm(“appointment”,null,parameters);

onLoad Script for new form which needs to be opened:

// Get the Value of the Regarding through the Customer Parameters
var param=Xrm.Page.context.getQueryStringParameters();
var regardingId=param["parameter_regardingid"];
var regardingName=param["parameter_regardingname"];
var regardingType=param["parameter_regardingtype"];
//Populate the Regarding if there is one
if (regardingId != undefined)

  {Xrm.Page.getAttribute(“regardingobjectid”).setValue([{id:regardingId, name:regardingName, entityType:regardingType}]);}