• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
MSCRM janmson
MS CRM顾问及二次开发
博客园    首页    新随笔    联系   管理    订阅  订阅

用javascript调用WebService,RetrieveDynamicEntity的方式取出EntityProperty的Value


 

 

function getDynamicEnitity(entityName, entityId,attributeNames)
{
    
var xml = "" + 
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + GenerateAuthenticationHeader()+"  <soap:Body>" + 
"    <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
"      <Request xsi:type=\"RetrieveRequest\" ReturnDynamicEntities=\"true\">" + 
"        <Target xsi:type=\"TargetRetrieveDynamic\">" + 
"          <EntityName>"+entityName+"</EntityName>" + 
"          <EntityId>"+entityId+"</EntityId>" + 
"        </Target>" + 
"        <ColumnSet xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:ColumnSet\">" + 
"          <q1:Attributes>" + 
getAttributeNamesString(attributeNames)+
"          </q1:Attributes>" + 
"        </ColumnSet>" + 

"      </Request>" + 
"    </Execute>" + 
"  </soap:Body>" + 
"</soap:Envelope>" + 
"";

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

xmlHttpRequest.Open(
"POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader(
"SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Execute");
xmlHttpRequest.setRequestHeader(
"Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader(
"Content-Length", xml.length);
xmlHttpRequest.send(xml);

var resultXml = xmlHttpRequest.responseXML;
return resultXml;
}

function getEntityPropertyValue(resultXml, attributeName)
{
// Create an XML object to parse the results.
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async
=false;
xmlDoc.loadXML(resultXml.xml);

var ret=xmlDoc.selectSingleNode("//Property[@Name='"+attributeName+"']");

//ret.text enough for return xml;
//
in other case this may not enough be careful for this.
if (ret!=null)
  return ret.text;
else
 return null;


}
function getAttributeNamesString(attributes)
{
   
   
var strRet="";
   
for(i=0;i<attributes.length;i++)
  {
    strRet
+=("<q1:Attribute>"+attributes[i]+"</q1:Attribute>") ;

    
  }
   
return strRet;
}

 

 

 

 

posted @ 2009-04-11 15:13  韩建兴  阅读(1531)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3