我一直在尝试解决一个问题,但我不知道 JavaScript,所以我在互联网上追逐我的尾巴。
我继承了一个 JavaScript 文件,该文件应该在对帐户制定计划时触发。每个帐户可以有多个计划,但一次只能有 1 个有效的计划。这意味着当您创建一个新的时,您应该只有在所有其他人都被停用的情况下才能使用。我们现在拥有的代码(见下文)仅查找计划的存在,而不管其状态如何。谁能帮我吗?
谢谢
checkActiveADP = function()
{
// check if there is a key account populated
if (Xrm.Page.getAttribute("new_keyaccountid").getValue() != null && Xrm.Page.ui.getFormType() == 1)
{
// get the id of the parent account of the account plan
var keyaccountid = Xrm.Page.getAttribute("new_keyaccountid").getValue()[0].id;
if (keyaccountid != null)
{
// build query to get all the account plans for the current parent account - if any
var filter = "/New_accountplanSet()?$filter=new_keyaccountid/Id eq guid'" + keyaccountid + "'";
var retrievedMultiple = CCrm.JSCore.RetrieveMultipleRequest(filter);
if (retrievedMultiple.results.length >=1)
{
alert("Active ADP already exists, please update that one or deactivate before creating a new one");
}
}
}
}