标签:
原创,转载请说明出处 王红福 http://www.cnblogs.com/hellohongfu/p/4792452.html
var clientUrl = "http://172.16.30.12:5555/teachnet"
//The XRM OData end-point
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
function retrieveRecord(id, odataSetName, successCallback, errorCallback)
{
//id is required
if (!id)
{
alert("record id is required.");
return;
}
else
{
id = encodeURIComponent(id);
}
//odataSetName is required, i.e. "AccountSet"
if (!odataSetName)
{
alert("odataSetName is required.");
return;
}
else
{ odataSetName = encodeURIComponent(odataSetName); }
console.log(clientUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid‘" + id + "‘)");
//Asynchronous AJAX function to Retrieve a CRM record using OData
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: clientUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid‘" + id + "‘)",
beforeSend: function (XMLHttpRequest)
{
//Specifying this header ensures that the results will be returned as JSON.
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest)
{
if (successCallback)
{
successCallback(data.d, textStatus, XmlHttpRequest);
}
},
error: function (XmlHttpRequest, textStatus, errorThrown)
{
if (errorCallback)
errorCallback(XmlHttpRequest, textStatus, errorThrown);
else
errorHandler(XmlHttpRequest, textStatus, errorThrown);
}
});
}
var rowTR=$($("iframe")[0].contentWindow.document).find("#headerRowTR")
var currentDoc=$($("iframe")[0].contentWindow.document);
var button ="<input id=‘detail‘ onclick=‘detailClick()‘ type=‘button‘ value=‘显示详细‘ >"
function detailClick(){
alert(‘test‘);
}
//var td =$($("iframe")[0].contentWindow.document).find(‘#chartDesignerCommandBar‘).last();
currentDoc.find("#contentContainer").html(" <iframe src=‘http://www.baidu.com‘ /> ");
currentDoc.find("#headerRowTR").html(‘‘).append(button);
function successCallBack(data){
console.log("successCallBack:"+data);
var contact=data;
var row =$("<div> FirstName : <input id=‘FirstName‘ type=‘text value=‘‘ ><br>LastName: <input id=‘LastName‘ type=‘text value=‘‘ ><br>Telephone1: <input id=‘Telephone1‘ type=‘text value=‘‘ ><br>EMailAddress1: <input id=‘EMailAddress1‘ type=‘text value=‘‘ ><br>Address1_Line1: <input id=‘Address1_Line1‘ type=‘text value=‘‘ ><br>Address1_City: <input id=‘Address1_City‘ type=‘text value=‘‘ ><br>Address1_StateOrProvince: <input id=‘Address1_StateOrProvince‘ type=‘text value=‘‘ ><br>Address1_PostalCode: <input id=‘Address1_PostalCode‘ type=‘text value=‘‘ ><br><input onclick=‘alert(‘chenggong‘)‘ value=‘Save‘ type=‘button‘></div>");
if (contact.FirstName)
row.find("#FirstName").attr("value", contact.FirstName);
if (contact.LastName)
row.find("#LastName").attr("value", contact.LastName);
if (contact.Telephone1)
row.find("#Telephone1").attr("value", contact.Telephone1);
if (contact.EMailAddress1)
row.find("#EMailAddress1").attr("value", contact.EMailAddress1);
if (contact.Address1_Line1)
row.find("#Address1_Line1").attr("value", contact.Address1_Line1);
if (contact.Address1_City)
row.find("#Address1_City").attr("value", contact.Address1_City);
if (contact.Address1_StateOrProvince)
row.find("#Address1_StateOrProvince").attr("value", contact.Address1_StateOrProvince);
if (contact.Address1_PostalCode)
row.find("#Address1_PostalCode").attr("value", contact.Address1_PostalCode);
currentDoc.find("#contentContainer").append(row);
}
function errorCallBack(data){
console.log("errorCallBack:"+data);
}
function SelectedOnChange(id){
currentDoc.find("#contentContainer").html(‘当前选择记录是: ‘+id);
retrieveRecord(id,‘ContactSet‘,successCallBack,errorCallBack)
}
var selectedId=‘‘;
function getSelectedId(){
var id =currentDoc.find(".ms-crm-List-SelectedRow").attr(‘oid‘);
if(id!=selectedId){
SelectedOnChange(id);
console.log(id);
}
selectedId=id;
}
setInterval("getSelectedId()",10)
最终效果
标签:
原文地址:http://www.cnblogs.com/hellohongfu/p/4792452.html