Opportunity altına eklenen bir not (annotation) varsa notes tabını görünür yapan ,eğer opportunity e ait daha önceden girilen bir not yoksa bu tabı gizleyen script aşagıdadır.
Burada sorgumuzu odataquery ile olusturduk.
ODataRetrieveMultipleAjax : Sorgu larımızı calıstıracagımız metot.
/*Gökhan Mentese-gkhnmnts@gmail.com*/
function NoteTabVisibleInOpportunity() {
try {
var entityid = GetEntityId();
var formType = Xrm.Page.ui.getFormType();
if (formType == 1) {
Xrm.Page.ui.tabs.get("notetabopportunity").setVisible(false);
}
else {
if (entityid != null) {
var query = "AnnotationSet?$filter=ObjectId/Id eq guid'" + ConverttoStringFromGuid(entityid) + "'";
var noteEntity = ODataRetrieveMultipleAjax(query);
if (noteEntity != null && noteEntity.results != null && noteEntity.results.length != null && noteEntity.results.length != 0) {
Xrm.Page.ui.tabs.get("notetabopportunity").setVisible(true);
}
else {
Xrm.Page.ui.tabs.get("notetabopportunity").setVisible(false);
}
}
}
} catch (e) {
alert("Function NoteTabVisibleInOpportunity() \n" +e.message);
}
}
function ODataRetrieveMultipleAjax(oDataSelect) {
var crmOrgSvc = GetCrmSvc();
var result = null;
oDataSelect = crmOrgSvc + oDataSelect;
jQuery.support.cors = true;
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: oDataSelect,
async: false,
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 (data != null && data.d != null) {
result = data.d;
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown, "Error Function:" + "ODataRetrieveMultipleAjax");
}
});
return result;
}
function GetCrmSvc() {
//return GetClientUrl() + "/xrmservices/2011/OrganizationData.svc/";
return Xrm.Page.context.prependOrgName("/xrmservices/2011/OrganizationData.svc/");
}
function GetEntityId() {
return Xrm.Page.data.entity.getId();
}
Hiç yorum yok:
Yorum Gönder