function associateManyToManyRecord_Sync_ByWebAPI(primaryEntityName, primaryEntityId, relatedEntityName, relatedEntityId, n2nRelationName) {
var primaryEntityPluralName = primaryEntityName;
var relatedEntityPluralName = relatedEntityName;
primaryEntityId = primaryEntityId.replace(/\{|\}/gi, '');
relatedEntityId = relatedEntityId.replace(/\{|\}/gi, '');
var association = {};
association["@odata.id"] = Xrm.Page.context.getClientUrl() + "/api/data/v8.2/" + relatedEntityPluralName + "(" + relatedEntityId + ")";
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/" + primaryEntityPluralName + "(" + primaryEntityId + ")/" + n2nRelationName + "/$ref", false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.send(JSON.stringify(association));
debugger;
if (req.status === 204 || this.status === 1223) {
//Success - No Return Data - Do Something
}
else if (req.status === 412) {
if (req.responseText != null && this.req != undefined) {
var errorResponse = JSON.parse(req.responseText);
if (errorResponse['error'] != null && errorResponse['error'] != undefined) {
if (errorResponse['error']['message'] != null && errorResponse['error']['message'] != undefined) {
var errorMessage = errorResponse['error']['message'];
alert(errorMessage);//-- 'A record with matching key values already exists.'
//if (errorMessage == 'A record with matching key values already exists.') {
// disassociateManyToManyRecords_Sync_ByWebAPI(primaryEntityName, primaryEntityId, relatedEntityName, relatedEntityId, n2nRelationName);
//}
}
}
}
}
else {
//parent.Xrm.Utility.alertDialog(this.statusText);
}
}
function disassociateManyToManyRecords_Sync_ByWebAPI(primaryEntityName, primaryEntityId, relatedEntityName, relatedEntityId, n2nRelationName) {
debugger;
var primaryEntityPluralName = primaryEntityName;
var relatedEntityPluralName = relatedEntityName;
primaryEntityId = primaryEntityId.replace(/\{|\}/gi, '');
relatedEntityId = relatedEntityId.replace(/\{|\}/gi, '');
var req = new XMLHttpRequest();
req.open("DELETE", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/" + primaryEntityPluralName + "(" + primaryEntityId + ")/" + n2nRelationName + "(" + relatedEntityId + ")/$ref", false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.send();
debugger;
if (req.status === 204 || req.status === 1223) {
} else {
var errorMsg = 'Some error occurred while disassociating records.';
}
}
function displayEnableCampaign() {
var selectionId = Xrm.Page.getAttribute("selection").getValue()[0].id;
selectionId = selectionId.replace("{", "").replace("}", "");
var type = Xrm.Page.ui.getFormType();
var campaignId = "";
var channeloutputId = "";
var removeTP = new XMLHttpRequest();
var removeTPURL = Xrm.Page.context.getClientUrl() + "/api/data/v9.1/selectionpocs()?$select=_targetselectionid_value&$filter=selectionpocid eq '" + selectionId + "'";
removeTP.open("GET", removeTPURL, false);
removeTP.setRequestHeader("OData-MaxVersion", "4.0");
removeTP.setRequestHeader("OData-Version", "4.0");
removeTP.setRequestHeader("Accept", "application/json");
removeTP.setRequestHeader("Content-Type", "application/json; charset=utf-8");
removeTP.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
removeTP.onreadystatechange = function () {
if (this.readyState === 4) {
removeTP.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var tags = result.value.length;
debugger;
campaignId = result.value[0]._targetselectionid_value;
}
}
};
removeTP.send();
if (campaignId != "" || campaignId != null) {
var removeTP = new XMLHttpRequest();
var removeTPURL = Xrm.Page.context.getClientUrl() + "/api/data/v9.1/campaigns()?$select=_campaignoutput_value,systemchecklockfield&$filter=campaignid eq '" + campaignId + "'";
removeTP.open("GET", removeTPURL, false);
removeTP.setRequestHeader("OData-MaxVersion", "4.0");
removeTP.setRequestHeader("OData-Version", "4.0");
removeTP.setRequestHeader("Accept", "application/json");
removeTP.setRequestHeader("Content-Type", "application/json; charset=utf-8");
removeTP.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
removeTP.onreadystatechange = function () {
if (this.readyState === 4) {
removeTP.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var tags = result.value.length;
debugger;
channeloutputId = result.value[0]._campaignoutput_value;
var systemchecklockfield = result.value[0].systemchecklockfield;
if (type != 1) {
if (systemchecklockfield != null) {
if (systemchecklockfield == true) {
DisableFormFields(true);
}
else DisableFormFields(false);
}
}
}
}
};
removeTP.send();
}
if (channeloutputId != "" || channeloutputId != null) {
var removeTP = new XMLHttpRequest();
var removeTPURL = Xrm.Page.context.getClientUrl() + "/api/data/v9.1/channeloutputitems()?$select=channel&$filter=_campaigntype_value eq '" + channeloutputId + "' and enable eq false";
removeTP.open("GET", removeTPURL, false);
removeTP.setRequestHeader("OData-MaxVersion", "4.0");
removeTP.setRequestHeader("OData-Version", "4.0");
removeTP.setRequestHeader("Accept", "application/json");
removeTP.setRequestHeader("Content-Type", "application/json; charset=utf-8");
removeTP.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
removeTP.onreadystatechange = function () {
if (this.readyState === 4) {
removeTP.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var tags = result.value.length;
debugger;
for (var i = 0; i < result.value.length; i++) {
Xrm.Page.getControl("touchpoint").removeOption(result.value[i].channel);
}
}
}
};
removeTP.send();
}
}
function DoesControlHaveAttribute(control) {
var controlType = control.getControlType();
return controlType != "iframe" && controlType != "webresource" && controlType != "subgrid";
}
function DisableFormFields(onOff) {
Xrm.Page.ui.controls.forEach(function (control, index) {
if (DoesControlHaveAttribute(control)) {
if (control.name == "controlgroupsize"
|| control.name == "channeldescription"
|| control.name == "nonprioritychanneldescription"
|| control.name == "targetbasesize"
|| control.name == "individualsizedetail"
|| control.name == "waterfallsizedetail"
|| control.name == "channelcount"
) {
control.setDisabled(true);
}
else if (control.name != "approve" && control.name != "rejectreason" && control.name != "terminatecampaignstatus") {
control.setDisabled(onOff);
}
else control.setDisabled(false);
}
});
}
function FrmOnSave(prmContext) {
var type = Xrm.Page.ui.getFormType();
var channelId = Xrm.Page.data.entity.getId();
channelId = channelId.replace("{", "").replace("}", "");
var touchpoint = Xrm.Page.getAttribute("touchpoint").getValue();
var selectionId = Xrm.Page.getAttribute("selection").getValue()[0].id;
selectionId = selectionId.replace("{", "").replace("}", "");
var withOptOutCustomer = Xrm.Page.getAttribute("withoptoutcustomer").getValue();
Xrm.Page.getControl("name").setDisabled(false);
Xrm.Page.getControl("touchpoint").setDisabled(false);
Xrm.Page.getControl("withoptoutcustomer").setDisabled(false);
if (withOptOutCustomer == true) {
var removeTP = new XMLHttpRequest();
var removeTPURL = Xrm.Page.context.getClientUrl() + "/api/data/v9.1/taggroups()?$select=name&$filter=selectiontype eq 4";
removeTP.open("GET", removeTPURL, false);
removeTP.setRequestHeader("OData-MaxVersion", "4.0");
removeTP.setRequestHeader("OData-Version", "4.0");
removeTP.setRequestHeader("Accept", "application/json");
removeTP.setRequestHeader("Content-Type", "application/json; charset=utf-8");
removeTP.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
removeTP.onreadystatechange = function () {
if (this.readyState === 4) {
removeTP.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var tags = result.value.length;
debugger;
for (var i = 0; i < result.value.length; i++) {
disassociateManyToManyRecords_Sync_ByWebAPI("prioritytagchannelgroups", channelId, "taggroups", result.value[i].taggroupid, "prioritytagchannelgroup_taggroup");
}
}
}
};
removeTP.send();
}
else {
var removeTP = new XMLHttpRequest();
var removeTPURL = Xrm.Page.context.getClientUrl() + "/api/data/v9.1/taggroups()?$select=name&$filter=selectiontype eq 4";
removeTP.open("GET", removeTPURL, false);
removeTP.setRequestHeader("OData-MaxVersion", "4.0");
removeTP.setRequestHeader("OData-Version", "4.0");
removeTP.setRequestHeader("Accept", "application/json");
removeTP.setRequestHeader("Content-Type", "application/json; charset=utf-8");
removeTP.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
removeTP.onreadystatechange = function () {
if (this.readyState === 4) {
removeTP.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var tags = result.value.length;
debugger;
for (var i = 0; i < result.value.length; i++) {
associateManyToManyRecord_Sync_ByWebAPI("prioritytagchannelgroups", channelId, "taggroups", result.value[i].taggroupid, "prioritytagchannelgroup_taggroup");
}
}
}
};
removeTP.send();
}
var removeTP = new XMLHttpRequest();
var removeTPURL = Xrm.Page.context.getClientUrl() + "/api/data/v9.1/taggroups()?$select=name&$filter=ischanneldefaultgroup eq true and touchpoint ne " + touchpoint + " and taggrouptype eq 2 ";
removeTP.open("GET", removeTPURL, false);
removeTP.setRequestHeader("OData-MaxVersion", "4.0");
removeTP.setRequestHeader("OData-Version", "4.0");
removeTP.setRequestHeader("Accept", "application/json");
removeTP.setRequestHeader("Content-Type", "application/json; charset=utf-8");
removeTP.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
removeTP.onreadystatechange = function () {
if (this.readyState === 4) {
removeTP.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var tags = result.value.length;
debugger;
for (var i = 0; i < result.value.length; i++) {
disassociateManyToManyRecords_Sync_ByWebAPI("prioritytagchannelgroups", channelId, "taggroups", result.value[i].taggroupid, "prioritytagchannelgroup_taggroup");
}
}
}
};
removeTP.send();
var AddTP = new XMLHttpRequest();
var AddTPURL = Xrm.Page.context.getClientUrl() + "/api/data/v9.1/taggroups()?$select=name&$filter=ischanneldefaultgroup eq true and touchpoint eq " + touchpoint + " and taggrouptype eq 2 ";
AddTP.open("GET", AddTPURL, false);
AddTP.setRequestHeader("OData-MaxVersion", "4.0");
AddTP.setRequestHeader("OData-Version", "4.0");
AddTP.setRequestHeader("Accept", "application/json");
AddTP.setRequestHeader("Content-Type", "application/json; charset=utf-8");
AddTP.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
AddTP.onreadystatechange = function () {
if (this.readyState === 4) {
AddTP.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var tags = result.value.length;
debugger;
for (var i = 0; i < result.value.length; i++) {
associateManyToManyRecord_Sync_ByWebAPI("prioritytagchannelgroups", channelId, "taggroups", result.value[i].taggroupid, "prioritytagchannelgroup_taggroup");
}
}
}
};
AddTP.send();
///
///Section Check touchpoint duplicate ///
///
isFound = false;
var req_checkTagRequest = new XMLHttpRequest();
var req_checkTagURL = Xrm.Page.context.getClientUrl() + "/api/data/v9.1/tagchannels()?$select=name&$filter=_selection_value eq '" + selectionId + "' and touchpoint eq " + touchpoint;
req_checkTagRequest.open("GET", req_checkTagURL, false);
req_checkTagRequest.setRequestHeader("OData-MaxVersion", "4.0");
req_checkTagRequest.setRequestHeader("OData-Version", "4.0");
req_checkTagRequest.setRequestHeader("Accept", "application/json");
req_checkTagRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req_checkTagRequest.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req_checkTagRequest.onreadystatechange = function () {
if (this.readyState === 4) {
req_checkTagRequest.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var tags = result.value.length;
debugger;
if (tags > 0) { //has duplication
isFound = true;
}
} else {
console.log(this.statusText);
}
}
};
req_checkTagRequest.send();
if (isFound == false) {
var req_checkTagRequest = new XMLHttpRequest();
var req_checkTagURL = Xrm.Page.context.getClientUrl() + "/api/data/v9.1/prioritytagchannelgroups()?$select=name&$filter=_selection_value eq '" + selectionId + "' and touchpoint eq " + touchpoint + " and prioritytagchannelgroupid ne '" + channelId + "'";
if (type == 1) {
req_checkTagURL = Xrm.Page.context.getClientUrl() + "/api/data/v9.1/prioritytagchannelgroups()?$select=name&$filter=_selection_value eq '" + selectionId + "' and touchpoint eq " + touchpoint;
}
req_checkTagRequest.open("GET", req_checkTagURL, false);
req_checkTagRequest.setRequestHeader("OData-MaxVersion", "4.0");
req_checkTagRequest.setRequestHeader("OData-Version", "4.0");
req_checkTagRequest.setRequestHeader("Accept", "application/json");
req_checkTagRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req_checkTagRequest.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req_checkTagRequest.onreadystatechange = function () {
if (this.readyState === 4) {
req_checkTagRequest.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var tags = result.value.length;
debugger;
if (tags > 0) { //has duplication
isFound = true;
}
} else {
console.log(this.statusText);
}
}
};
req_checkTagRequest.send();
}
if (isFound == true) {
Xrm.Page.ui.setFormNotification("This marketing touchpoint has been setup in this selection already", "ERROR", "3");
alert("This marketing touchpoint has been setup in this selection already");
}
///
///Section Check any tagging apply //
///
var channelId = Xrm.Page.data.entity.getId();
channelId = channelId.replace("{", "").replace("}", "");
if (type != 1) {
var req_checkTagRequest = new XMLHttpRequest();
var req_checkTagURL = Xrm.Page.context.getClientUrl() + "/api/data/v9.1/prioritytagchannelgroups()?$expand=prioritytagchannelgroup_taggroup($select=name)&$select=prioritytagchannelgroup_taggroup&$filter=prioritytagchannelgroupid eq '" + channelId + "'";
req_checkTagRequest.open("GET", req_checkTagURL, false);
req_checkTagRequest.setRequestHeader("OData-MaxVersion", "4.0");
req_checkTagRequest.setRequestHeader("OData-Version", "4.0");
req_checkTagRequest.setRequestHeader("Accept", "application/json");
req_checkTagRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req_checkTagRequest.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req_checkTagRequest.onreadystatechange = function () {
if (this.readyState === 4) {
req_checkTagRequest.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var tags = result.value[0].prioritytagchannelgroup_taggroup.length;
debugger;
if (tags == 0) { //has duplication
Xrm.Page.ui.setFormNotification("No tag(s) is selected", "ERROR", "3");
alert("No tag(s) is selected");
}
else {
Xrm.Page.ui.clearFormNotification("3");
}
} else {
console.log(this.statusText);
}
}
};
req_checkTagRequest.send();
}
///
//Section Rearrange the Order
///
var sectionId = Xrm.Page.getAttribute("selection").getValue()[0].id;
var saveEvent = prmContext.getEventArgs();
var order = 0;
var preOrder;
sectionId = sectionId.replace("{", "").replace("}", "");
var req = new XMLHttpRequest();
var requestURL = Xrm.Page.context.getClientUrl() + "/api/data/v8.1/prioritytagchannelgroups()?$select=order&$filter=_selection_value eq '" + sectionId + "'";
req.open("GET", requestURL, false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
preOrder = result.order;
if (result.value.length > 0) { //has duplication
order = result.value.length;
}
} else {
console.log(this.statusText);
isdul = false;
}
}
};
req.send();
if (type != 1) {
channelId = Xrm.Page.data.entity.getId();
channelId = channelId.replace("{", "").replace("}", "");
var req = new XMLHttpRequest();
var requestURL = Xrm.Page.context.getClientUrl() + "/api/data/v8.1/prioritytagchannelgroups()?$top=1&$select=order&$filter=prioritytagchannelgroupid eq '" + channelId + "'";
req.open("GET", requestURL, false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
preOrder = result.value[0].order;
} else {
console.log(this.statusText);
}
}
};
req.send();
}
if (Xrm.Page.getAttribute("order").getValue() == null) {
order++;
Xrm.Page.getAttribute("order").setValue(order);
} else {
if (Xrm.Page.getAttribute("order").getValue() > order) {
if (type != 1) {
Xrm.Page.ui.setFormNotification("Can not input number larger than " + order, "ERROR", "3");
saveEvent.preventDefault();
}
} else {
if (type != 1) {
if (preOrder != Xrm.Page.getAttribute("order").getValue()) {
var updatedpriorityChannel;
var req = new XMLHttpRequest();
var requestURL = Xrm.Page.context.getClientUrl() + "/api/data/v8.1/prioritytagchannelgroups()?$top=1&$select=prioritytagchannelgroupid&$filter=_selection_value eq '" + sectionId + "'" + ' and order eq ' + Xrm.Page.getAttribute("order").getValue();
req.open("GET", requestURL, false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
updatedpriorityChannel = result.value[0].prioritytagchannelgroupid;
} else {
console.log(this.statusText);
}
}
};
req.send();
var data = { "order": preOrder };
Xrm.WebApi.updateRecord("prioritytagchannelgroup", updatedpriorityChannel, data).then(
function success(result) {
console.log("success");
},
function (error) {
console.log(error.message);
}
);
}
}
}
}
}
function FormDisplay() {
var type = Xrm.Page.ui.getFormType();
Xrm.Page.getControl("name").setDisabled(false);
Xrm.Page.getControl("touchpoint").setDisabled(false);
Xrm.Page.getControl("withoptoutcustomer").setDisabled(false);
if (type == 1) {
Xrm.Page.getControl("order").setDisabled(true);
} else {
Xrm.Page.getControl("order").setDisabled(false);
}
displayEnableCampaign();
setTimeout(FormDisplay, 2000);
}
// added by Jeff.Lai on 20220330
function AddTagGroupRulesToChannelTags(_channelId,_taggroupid) {
if (_channelId == null) {
return null;
}
var addRequest = new XMLHttpRequest();
var GetTagURL = Xrm.Page.context.getClientUrl() + "/api/data/v9.1/taggroups?$select=name&$filter=selectiontype eq 4";
addRequest.open("GET", GetTagURL, false);
addRequest.setRequestHeader("OData-MaxVersion", "4.0");
addRequest.setRequestHeader("OData-Version", "4.0");
addRequest.setRequestHeader("Accept", "application/json");
addRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
addRequest.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
addRequest.onreadystatechange = function () {
if (this.readyState === 4) {
addRequest.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var tags = result.value.length;
debugger;
for (var i = 0; i < result.value.length; i++) {
disassociateManyToManyRecords_Sync_ByWebAPI("prioritytagchannelgroups", channelId, "taggroups", result.value[i].taggroupid, "prioritytagchannelgroup_taggroup");
}
}
}
};
removeTP.send();
}
function displaylinkedoffer() {
var viewId = "{00000000-0000-0000-0000-000000000001}";
var entName = "tagoffer";
var vwName = "Job Resources";
var selectionId = Xrm.Page.getAttribute("selection").getValue()[0].id.replace("{", "").replace("}", "");
var resFetch = "<fetch version='1.0' output-format='xml-platform' mapping='logical' >" +
"<entity name='tagoffer'>" +
"<attribute name='name' />" +
"<attribute name='createdon' />" +
"<filter>" +
"<condition attribute='selectiontagofferid' operator='eq' value='" + selectionId + "' />" +
"</filter>" +
"</entity>" +
"</fetch>";
var resLayout = "<grid name='resultset' object='10030' jump='name' select='1' icon='1' preview='1'>" +
"<row name='result' id='tagoffer'>" +
"<cell name='name' width='200'/>" +
"<cell name='createdon' width='125'/>" +
"</row>" +
"</grid>";
Xrm.Page.getControl("linkedoffer").addCustomView(viewId, entName, vwName, resFetch, resLayout, true);
}
function onLoad() {
Xrm.Page.data.entity.refresh();
var type = Xrm.Page.ui.getFormType();
if (type == 1) {
Xrm.Page.getControl("order").setDisabled(true);
Xrm.Page.ui.tabs.get("General").sections.get("ConnectMessage").setVisible(false);
Xrm.Page.ui.tabs.get("General").sections.get("EACMessage").setVisible(false);
Xrm.Page.ui.tabs.get("General").sections.get("ECMUnicornMessage").setVisible(false);
Xrm.Page.ui.tabs.get("General").sections.get("iEngageMessage").setVisible(false);
Xrm.Page.ui.tabs.get("General").sections.get("iPoSMessage").setVisible(false);
} else {
Xrm.Page.getControl("order").setDisabled(false);
ChangeTouchPoint();
}
var channelId = Xrm.Page.data.entity.getId();
channelId = channelId.replace("{", "").replace("}", "");
var touchpoint = Xrm.Page.getAttribute("touchpoint").getValue();
var selectionId = Xrm.Page.getAttribute("selection").getValue()[0].id;
selectionId = selectionId.replace("{", "").replace("}", "");
displaylinkedoffer();
if (type != 1) {
var withOptOutCustomer = Xrm.Page.getAttribute("withoptoutcustomer").getValue();
if (withOptOutCustomer == true) {
var removeTP = new XMLHttpRequest();
var removeTPURL = Xrm.Page.context.getClientUrl() + "/api/data/v9.1/taggroups()?$select=name&$filter=selectiontype eq 4";
removeTP.open("GET", removeTPURL, false);
removeTP.setRequestHeader("OData-MaxVersion", "4.0");
removeTP.setRequestHeader("OData-Version", "4.0");
removeTP.setRequestHeader("Accept", "application/json");
removeTP.setRequestHeader("Content-Type", "application/json; charset=utf-8");
removeTP.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
removeTP.onreadystatechange = function () {
if (this.readyState === 4) {
removeTP.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var tags = result.value.length;
debugger;
for (var i = 0; i < result.value.length; i++) {
disassociateManyToManyRecords_Sync_ByWebAPI("prioritytagchannelgroups", channelId, "taggroups", result.value[i].taggroupid, "prioritytagchannelgroup_taggroup");
}
}
}
};
removeTP.send();
}
else {
var removeTP = new XMLHttpRequest();
var removeTPURL = Xrm.Page.context.getClientUrl() + "/api/data/v9.1/taggroups()?$select=name&$filter=selectiontype eq 4";
removeTP.open("GET", removeTPURL, false);
removeTP.setRequestHeader("OData-MaxVersion", "4.0");
removeTP.setRequestHeader("OData-Version", "4.0");
removeTP.setRequestHeader("Accept", "application/json");
removeTP.setRequestHeader("Content-Type", "application/json; charset=utf-8");
removeTP.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
removeTP.onreadystatechange = function () {
if (this.readyState === 4) {
removeTP.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var tags = result.value.length;
debugger;
for (var i = 0; i < result.value.length; i++) {
associateManyToManyRecord_Sync_ByWebAPI("prioritytagchannelgroups", channelId, "taggroups", result.value[i].taggroupid, "prioritytagchannelgroup_taggroup");
}
}
}
};
removeTP.send();
}
var removeTP = new XMLHttpRequest();
var removeTPURL = Xrm.Page.context.getClientUrl() + "/api/data/v9.1/taggroups()?$select=name&$filter=ischanneldefaultgroup eq true and touchpoint ne " + touchpoint + " and taggrouptype eq 2 ";
removeTP.open("GET", removeTPURL, false);
removeTP.setRequestHeader("OData-MaxVersion", "4.0");
removeTP.setRequestHeader("OData-Version", "4.0");
removeTP.setRequestHeader("Accept", "application/json");
removeTP.setRequestHeader("Content-Type", "application/json; charset=utf-8");
removeTP.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
removeTP.onreadystatechange = function () {
if (this.readyState === 4) {
removeTP.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var tags = result.value.length;
debugger;
for (var i = 0; i < result.value.length; i++) {
disassociateManyToManyRecords_Sync_ByWebAPI("prioritytagchannelgroups", channelId, "taggroups", result.value[i].taggroupid, "prioritytagchannelgroup_taggroup");
}
}
}
};
removeTP.send();
var AddTP = new XMLHttpRequest();
var AddTPURL = Xrm.Page.context.getClientUrl() + "/api/data/v9.1/taggroups()?$select=name&$filter=ischanneldefaultgroup eq true and touchpoint eq " + touchpoint + " and taggrouptype eq 2 ";
AddTP.open("GET", AddTPURL, false);
AddTP.setRequestHeader("OData-MaxVersion", "4.0");
AddTP.setRequestHeader("OData-Version", "4.0");
AddTP.setRequestHeader("Accept", "application/json");
AddTP.setRequestHeader("Content-Type", "application/json; charset=utf-8");
AddTP.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
AddTP.onreadystatechange = function () {
if (this.readyState === 4) {
AddTP.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var tags = result.value.length;
debugger;
for (var i = 0; i < result.value.length; i++) {
associateManyToManyRecord_Sync_ByWebAPI("prioritytagchannelgroups", channelId, "taggroups", result.value[i].taggroupid, "prioritytagchannelgroup_taggroup");
}
}
}
};
AddTP.send();
}
FormDisplay();
}
function Copy() {
debugger;
Xrm.Page.getAttribute("copy").setValue(true);
Xrm.Page.data.save().then(
function () {
//Xrm.Utility.alertDialog("Record saved");
var channelId = Xrm.Page.data.entity.getId();
channelId = channelId.replace("{", "").replace("}", "");
var copyid = '';
var version = Xrm.Page.getAttribute("version").getValue();
var touchpoint = Xrm.Page.getAttribute("touchpoint").getValue();
var findId = channelId + version + touchpoint;
setTimeout(function () { var a = 0; }, 3000);
Xrm.Page.getAttribute("copy").setValue(false);
Xrm.Page.data.entity.save();
},
function (error) {
Xrm.Utility.alertDialog(error.message);
});
}
function ChangeTouchPoint() {
var touchpoint = Xrm.Page.getAttribute("touchpoint").getValue();
if (touchpoint == 0) {
Xrm.Page.ui.tabs.get("General").sections.get("ConnectMessage").setVisible(true);
}
else {
Xrm.Page.ui.tabs.get("General").sections.get("ConnectMessage").setVisible(false);
}
if (touchpoint == 2) {
Xrm.Page.ui.tabs.get("General").sections.get("EACMessage").setVisible(true);
}
else {
Xrm.Page.ui.tabs.get("General").sections.get("EACMessage").setVisible(false);
}
if (touchpoint == 18) {
Xrm.Page.ui.tabs.get("General").sections.get("ECMUnicornMessage").setVisible(true);
}
else {
Xrm.Page.ui.tabs.get("General").sections.get("ECMUnicornMessage").setVisible(false);
}
if (touchpoint == 6) {
Xrm.Page.ui.tabs.get("General").sections.get("iEngageMessage").setVisible(true);
}
else {
Xrm.Page.ui.tabs.get("General").sections.get("iEngageMessage").setVisible(false);
}
if (touchpoint == 8) {
Xrm.Page.ui.tabs.get("General").sections.get("iPoSMessage").setVisible(true);
}
else {
Xrm.Page.ui.tabs.get("General").sections.get("iPoSMessage").setVisible(false);
}
}
function makeRequest(query) {
var serverUrl = Xrm.Page.context.getClientUrl();
var oDataEndpointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/";
oDataEndpointUrl += query;
var service = GetRequestObject();
if (service != null) {
service.open("GET", oDataEndpointUrl, false);
service.setRequestHeader("X-Requested-With", "XMLHttpRequest");
service.setRequestHeader("Accept", "application/json, text/javascript, */*");
service.send(null);
var retrieved = JSON.parse(service.responseText).d;
var results = new Array();
for (var i = 0; i < retrieved.results.length; i++) {
results.push(retrieved.results[i]);
}
return results;
}
return null;
}
function GetRequestObject() {
if (window.XMLHttpRequest) {
return new window.XMLHttpRequest;
} else {
try {
return new ActiveXObject("MSXML2.XMLHTTP.3.0");
} catch (ex) {
return null;
}
}
}