无法使用js crm 2016清除查找值

时间:2018-05-10 12:22:30

标签: javascript dynamics-crm lookup dynamics-crm-2016 xrm

我正在使用Dynamics crm 2016,在onChange事件之后,我调用了一个检查某些术语的函数,并根据这些术语清除了查找字段。问题是查找不清楚......我的代码中的问题在哪里?

function preventSavinf3940category(){    
if(Xrm.Page.getAttribute("new_activitycategory1id") == null){ // this if is false even after setValue to null
return;
}
         var category1 =  Xrm.Page.getAttribute("new_activitycategory1id").getValue();
         var category1Data =  category1[0].id;                           
         var students = getId(1);
         var teachers = getId(2);                
         if(category1Data == teachers || category1Data== students)
             {
              Xrm.Page.getAttribute("new_activitycategory1id").setValue(null);- doesn't clear the field
               alert("this category is not in use anymore")
             }

    }

1 个答案:

答案 0 :(得分:2)

更改以下行

if(Xrm.Page.getAttribute("new_activitycategory1id") == null){ // this if is false even after setValue to null
像这样

if(Xrm.Page.getAttribute("new_activitycategory1id") != null && Xrm.Page.getAttribute("new_activitycategory1id").getValue() == null){