I am trying to clear a lookup field using JS, when I run my code I get an alert -> an error happened please retry. when I tested my code in Developer mode after this line :
Xrm.Page.getAttribute("new_activitycategory1id").setValue(null); The function starts again (for no reason) and the field is not cleared (with out this line I get no errors).
my function triggered from onChange event in my JS code, the function works fine and the IF is right, but the setValue line is problematic... I don't understand why.
my code:
function preventSavinf3940category(){
if(Xrm.Page.getAttribute("new_activitycategory1id") == null){ // this if is alwaus 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);
alert("this category is not in use anymore")
}
}
*This post is locked for comments
I have the same question (0)