To show dialog box in current entity

Dialog box in current entity

If Opportunity is won then show alert box and two buttons "yes or no", if "yes" then get current accountid and open account form. else if "no" then no action taken.

to check whether the Opportunity is won or loss.

function showConfirmDialog() {
debugger;
var statecode = Xrm.Page.getAttribute('statecode').getValue();
//alert(statecode);
if (statecode != null)
{
 // Won
 if (statecode == 1)
  {
     alert("won");
  }
else if(statecode == 2)
 {
   alert("Lost");
 }
 }
}

To perform action based on statecode.
function showConfirmDialog() {
debugger;
var statecode = Xrm.Page.getAttribute('statecode').getValue();
//alert(statecode);
if (statecode != null)
{
 // Won
 if (statecode == 1)
 {
  //alert(statecode);
    Xrm.Utility.confirmDialog("Click Yes or No to set the Personal Notes Value",
        function() {
            //alert("yes");
var currentaccid= Xrm.Page.getAttribute("parentaccountid").getValue()[0].id;
var currentaccname=Xrm.Page.getAttribute("parentaccountid").getValue()[0].name;
//alert(currentaccid);
//alert(currentaccname);
Xrm.Utility.openEntityForm( "account" , currentaccid);
//Xrm.Page.getAttribute("description").setValue("Yes");
        },
        function() {
           // Xrm.Page.getAttribute("description").setValue("No");
   });
 }
}
}

Subgrid access to count the one column and make total

ACCESS SUBGRID TO COUNT THE COLUMN AND SUM

SCENARIO:- Required total of field(priceperunit) in subgrid through javascript

Solution-I had executed below script.

//Xrm.Page.getControl('salesorderdetailsGrid').getGrid().getRows().get(i).getData().getEntity().getAttributes().get('priceperunit').getValue();

      I counted the grid total and based on count i fetched the data of 'priceperunit' data and total all the records present in sub grid.

function CostOfTotal()
{
debugger;
if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("salesorderdetailsGrid") != null && Xrm.Page.getControl("salesorderdetailsGrid") != undefined) {
//if subgrid is not null then counts the grid total
 var count = Xrm.Page.getControl("salesorderdetailsGrid").getGrid().getTotalRecordCount();
 alert("Total Products:"+count);
for(i = 0; i < count; i++) {
//to get control on grid count, which coloum you need to fetch data(like i used priceperunit)
var gridControl = Xrm.Page.getControl('salesorderdetailsGrid').getGrid().getRows().get(i).getData().getEntity().getAttributes().get('priceperunit').getValue();
alert(gridControl );
var cellValue = gridControl;
alert(cellValue);
cellValue = cellValue.replace( /,/,"." );
alert(cellValue);
var sum = sum + parseFloat(cellValue);
alert(sum);
}
}
//to set value in field.
Xrm.Page.getAttribute('new_total').setValue(sum);
}

Currency converter through in Dynamics CRM

To make currency convert into different country currencies in Dynamics CRM. I developed this below javascript.

 function convert(){
debugger;
// YOUR_APP_ID='API_KEY';
 $.ajax({
    url: 'https://openexchangerates.org/api/latest.json?app_id=API_KEY', 
    type: 'POST',
  success: function(data) {
        // exchange rata data is stored in json.quotes
        alert(data.rates.INR);
        // base currency is stored in json.base
        alert(data.base);
        // timestamp can be accessed in json.timestamp
        alert(data.timestamp);

var INR =data.rates.INR;
var USD = data.rates.USD;
var EURO= data.rates.INR;

var txtINR =Xrm.Page.getAttribute("new_inr").getValue();
var txtUSD =Xrm.Page.getAttribute("new_dollar").getValue();
var txtEURO = Xrm.Page.getAttribute("new_euro").getValue();
//from inr to usd and dollar
if(txtINR != null)
{
var val = parseFloat(txtINR).toFixed(2);
//INR to USD
var inrtousd = (1/INR)*val;
alert(inrtousd);
//INR to EURO
var inrtoeuro = (EURO/INR)*val;
alert(inrtoeuro);
break;
}
else if(txtUSD != null)
{
//from usd to inr,euro
var val1 = parseFloat(txtUSD).toFixed(2);
//USD to INR
var ustoinr = val1*INR;
alert(ustoinr);
//USD to EURO
var ustoeuro =val1*EURO;
alert(ustoeuro);
break;
}
else if(txtEURO !=null)
{
//from euro to inr,usd
var val2= parseFloat(txtEURO).toFixed(2);
//EURO TO INR
var eurotoinr = (INR/EURO)*val2;
alert(eurotoinr);
//EURO TO USD
var eurotousd(1/EURO)*val2;
alert(eurotousd);
break;
}
    }
  });
  }