scheduledstart == null
,则该字段不会由API返回。这是我的两段代码:
using get: bad request, querystring oveload
var encodedFetchXml2 = encodeURI(fetchXml);
var queryPath2 = "/api/data/v8.2/" + entityName + "s?fetchXml=" + encodedFetchXml2;
var requestPath2 = Xrm.Page.context.getClientUrl() + queryPath2;
var result2 = [];
var req2 = new XMLHttpRequest();
req2.open("GET", requestPath2, false); // false: synchronous
req2.setRequestHeader("Accept", "application/json");
req2.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req2.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req2.onreadystatechange = function () {
if (this.readyState === 4) {
this.onreadystatechange = null;
if (this.status === 200) {
var returned2 = JSON.parse(this.responseText);
result2 = returned2.value;
}
else {
alert(this.statusText);
console.log(requestPath);
}
}
};
req2.send();
return result2;
使用帖子:奇怪的行为
var result = [];
var encodedFetchXml = encodeURI(fetchXml);
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/$batch", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "multipart/mixed;boundary=batch_" + entityName + "fetch");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var response = JSON.parse(this.response.substring(this.response.indexOf('{'), this.response.lastIndexOf('}') + 1));
result = response.value;
//var returned = JSON.parse(this.responseText);
//result = returned.value;
} else {
alert(this.statusText);
console.log(requestPath);
}
}
};
var body = '--batch_' + entityName + 'fetch\n'
body += 'Content-Type: application/http\n'
body += 'Content-Transfer-Encoding: binary\n'
body += '\n'
body += 'GET ' + Xrm.Page.context.getClientUrl() + '/api/data/v8.2/' + entityName + 's?fetchXml='+ encodedFetchXml+' HTTP/1.1\n'
body += 'Content-Type: application/json\n'
body += 'OData-Version: 4.0\n'
body += 'OData-MaxVersion: 4.0\n'
body += 'Prefer: odata.include-annotations="*"\n'
body += '\n'
body += '--batch_' + entityName + 'fetch--'
req.send(body);
return result;
希望有人知道答案。
谢谢。
答案 0 :(得分:0)
使用提琴手,根据第一个检索到的记录是否为空,我对同一请求得到不同的响应
fetchxml
<fetch mapping="logical" >
<entity name="annotation" >
<attribute name="annotationid" />
<attribute name="createdby" />
<attribute name="createdon" />
<attribute name="modifiedby" />
<attribute name="modifiedon" />
<attribute name="subject" />
<attribute name="notetext" />
<attribute name="filename" />
<attribute name="objectid" />
<order attribute="createdon" descending="true" />
<filter type="or" />
<link-entity name="hamiav_position" from="hamiav_positionid" to="objectid" link-type="inner" alias="rela" >
<filter type="or" >
<condition attribute="hamiav_positionid" operator="in" >
<value uitype="hamiav_position" >
A267205E-222E-E911-80FC-005056B700A7
</value>
</condition>
</filter>
</link-entity>
</entity>
第一个记录在主题和注释文本中都有值
"@odata.context":"http://hamsrv14:5555/HAMS/api/data/v8.2/$metadata#annotations(_modifiedby_value,_objectid_value,objectid_hamiav_position,modifiedon,notetext,createdon,_createdby_value,filename,objecttypecode,subject,annotationid)","value":[
"@odata.etag":"W/\"67757686\"","_modifiedby_value@OData.Community.Display.V1.FormattedValue":"Fernando Garc\u00eda","_modifiedby_value@Microsoft.Dynamics.CRM.lookuplogicalname":"systemuser","_modifiedby_value":"1d88be59-7f05-e711-80c8-005056b700a7","_objectid_value@OData.Community.Display.V1.FormattedValue":null,"_objectid_value@Microsoft.Dynamics.CRM.associatednavigationproperty":"objectid_hamiav_position","_objectid_value@Microsoft.Dynamics.CRM.lookuplogicalname":"hamiav_position","_objectid_value":"a267205e-222e-e911-80fc-005056b700a7","modifiedon@OData.Community.Display.V1.FormattedValue":"10/06/2019 10:46","modifiedon":"2019-06-10T08:46:19Z","notetext":".","createdon@OData.Community.Display.V1.FormattedValue":"10/06/2019 10:46","createdon":"2019-06-10T08:46:19Z","_createdby_value@OData.Community.Display.V1.FormattedValue":"Fernando Garc\u00eda","_createdby_value@Microsoft.Dynamics.CRM.lookuplogicalname":"systemuser","_createdby_value":"1d88be59-7f05-e711-80c8-005056b700a7","filename":"AER-AR-01-092_full asset valuation_feb 2019_FR 31090-31089-31085-31084_PARQUEVAL S.L.jpg","objecttypecode@OData.Community.Display.V1.FormattedValue":"Position","objecttypecode":"hamiav_position","subject":".","annotationid":"19460037-5c8b-e911-8105-005056b700a7","objectid_hamiav_position":{
"hamiav_assetmanager":null,"_modifiedby_value":null,"hamiav_totalprincipal_state":null,"_ownerid_value":null,"_owningteam_value":null,"statuscode":null,"timezoneruleversionnumber":null,"hamiav_hams_positionid":null,"_createdonbehalfby_value":null,"hamiav_totalprincipal":null,"hamiav_liveoutstandingbalance_state":null,"_transactioncurrencyid_value":null,"statecode":null,"hamiav_totalaccruedinterest_state":null,"hamiav_hams_portfolioid":null,"hamiav_numberofassets_state":null,"hamiav_liveoutstandingbalance_base":null,"_hamiav_subportfolioid_value":null,"_modifiedonbehalfby_value":null,"hamiav_amrecoverystatus":null,"hamiav_totalprincipal_base":null,"hamiav_numberofassets":null,"hamiav_hams_owner":null,"hamiav_mainparticipant":null,"hamiav_portfolio":null,"hamiav_name":null,"hamiav_numberofparticipants":null,"hamiav_mainparticipantnif":null,"_owninguser_value":null,"hamiav_totalaccruedinterest_base":null,"hamiav_positionid":"a267205e-222e-e911-80fc-005056b700a7","_owningbusinessunit_value":null,"hamiav_liveoutstandingbalance":null,"versionnumber":null,"modifiedon":null,"hamiav_contactstatus":null,"hamiav_recoverystrategy":null,"utcconversiontimezonecode":null,"_createdby_value":null,"exchangerate":null,"hamiav_numberofrelatedcontracts":null,"hamiav_totalprincipal_date":null,"createdon":null,"hamiav_numberofrelatedcontracts_date":null,"hamiav_subportfoliocobra":null,"hamiav_numberofrelatedcontracts_state":null,"_hamiav_portfolioid_value":null,"hamiav_totalaccruedinterest":null,"overriddencreatedon":null,"hamiav_numberofassets_date":null,"hamiav_totalaccruedinterest_date":null,"hamiav_liveoutstandingbalance_date":null,"_hamiav_assetmanagerid_value":null,"importsequencenumber":null,"_hamiav_mainparticipantid_value":null,"hamiav_code":null,"hamiav_subportfolio":null,"hamiav_assetmanagername":null
}
},
我插入了一条没有主题和注释文本值的新记录,因此第一条记录不包含该字段的值,并且响应为:
"@odata.context":"http://hamsrv14:5555/HAMS/api/data/v8.2/$metadata#annotations(_modifiedby_value,_objectid_value,objectid_hamiav_position,modifiedon,createdon,_createdby_value,filename,objecttypecode,annotationid)","value":[
{
"@odata.etag":"W/\"67757548\"","_modifiedby_value@OData.Community.Display.V1.FormattedValue":"Fernando Garc\u00eda","_modifiedby_value@Microsoft.Dynamics.CRM.lookuplogicalname":"systemuser","_modifiedby_value":"1d88be59-7f05-e711-80c8-005056b700a7","_objectid_value@OData.Community.Display.V1.FormattedValue":null,"_objectid_value@Microsoft.Dynamics.CRM.associatednavigationproperty":"objectid_hamiav_position","_objectid_value@Microsoft.Dynamics.CRM.lookuplogicalname":"hamiav_position","_objectid_value":"a267205e-222e-e911-80fc-005056b700a7","modifiedon@OData.Community.Display.V1.FormattedValue":"10/06/2019 10:14","modifiedon":"2019-06-10T08:14:28Z","createdon@OData.Community.Display.V1.FormattedValue":"10/06/2019 10:14","createdon":"2019-06-10T08:14:28Z","_createdby_value@OData.Community.Display.V1.FormattedValue":"Fernando Garc\u00eda","_createdby_value@Microsoft.Dynamics.CRM.lookuplogicalname":"systemuser","_createdby_value":"1d88be59-7f05-e711-80c8-005056b700a7","filename":"AER-AR-01-092_full asset valuation_feb 2019_FR 31090-31089-31085-31084_PARQUEVAL S.L.jpg","objecttypecode@OData.Community.Display.V1.FormattedValue":"Position","objecttypecode":"hamiav_position","annotationid":"2e4ef9c3-578b-e911-8105-005056b700a7","objectid_hamiav_position":{
"hamiav_assetmanager":null,"_modifiedby_value":null,"hamiav_totalprincipal_state":null,"_ownerid_value":null,"_owningteam_value":null,"statuscode":null,"timezoneruleversionnumber":null,"hamiav_hams_positionid":null,"_createdonbehalfby_value":null,"hamiav_totalprincipal":null,"hamiav_liveoutstandingbalance_state":null,"_transactioncurrencyid_value":null,"statecode":null,"hamiav_totalaccruedinterest_state":null,"hamiav_hams_portfolioid":null,"hamiav_numberofassets_state":null,"hamiav_liveoutstandingbalance_base":null,"_hamiav_subportfolioid_value":null,"_modifiedonbehalfby_value":null,"hamiav_amrecoverystatus":null,"hamiav_totalprincipal_base":null,"hamiav_numberofassets":null,"hamiav_hams_owner":null,"hamiav_mainparticipant":null,"hamiav_portfolio":null,"hamiav_name":null,"hamiav_numberofparticipants":null,"hamiav_mainparticipantnif":null,"_owninguser_value":null,"hamiav_totalaccruedinterest_base":null,"hamiav_positionid":"a267205e-222e-e911-80fc-005056b700a7","_owningbusinessunit_value":null,"hamiav_liveoutstandingbalance":null,"versionnumber":null,"modifiedon":null,"hamiav_contactstatus":null,"hamiav_recoverystrategy":null,"utcconversiontimezonecode":null,"_createdby_value":null,"exchangerate":null,"hamiav_numberofrelatedcontracts":null,"hamiav_totalprincipal_date":null,"createdon":null,"hamiav_numberofrelatedcontracts_date":null,"hamiav_subportfoliocobra":null,"hamiav_numberofrelatedcontracts_state":null,"_hamiav_portfolioid_value":null,"hamiav_totalaccruedinterest":null,"overriddencreatedon":null,"hamiav_numberofassets_date":null,"hamiav_totalaccruedinterest_date":null,"hamiav_liveoutstandingbalance_date":null,"_hamiav_assetmanagerid_value":null,"importsequencenumber":null,"_hamiav_mainparticipantid_value":null,"hamiav_code":null,"hamiav_subportfolio":null,"hamiav_assetmanagername":null
}
}