1

私は何年もの間問題を解決しようとしてきましたが、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");                             
            }
        }
    }
}
4

3 に答える 3

1

次のように、アクティブ状態フィルター ( StateCode/Value eq 0) をOData filter変数に追加する必要があります。

        var filter = "/New_accountplanSet()?$filter=new_keyaccountid/Id eq guid'" + keyaccountid + "' and StateCode/Value eq 0";
        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");
        }

結果には、有効なアカウント プランのレコードのみが含まれます (存在する場合)。

于 2013-08-13T19:10:19.450 に答える
0

コードは次のようになります。else 条件を後に追加retrievedMultiple != null || retrievedMultiple.results != nullして、クエリに問題がないことを確認します。

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 != null || retrievedMultiple.results != null) 
            {
               for(var i = 0;i<retrievedMultiple.results.length; i++)
               {
                   if(retrievedMultiple.results[i]["statecode"] == 0)
                   {
                       alert("Active ADP already exists, please update that one or deactivate before creating a new one");
                   }
               }                            
            }
        }
    }
}
于 2013-08-12T15:17:39.743 に答える
0

retrievedMultiple.results配列です。アイテムに対して for ループを実行し、ステータスがアクティブかどうかを確認する必要があります。

于 2013-08-12T14:37:12.593 に答える