mercredi 26 août 2015

MSCRM 2011 Javascript condition issue

I have a problem with putting condition on javascript. In case form I'm using below code. When i enter material code manually everything is ok but when i use search help it gives me an error. When i check it on debugger i see 2 situations based on my method of entering code. Can you help me to improve my code below, its not working properly. Gives me error on step if (lookuptextvalue.name_Value.value)if i enter material code using search help.

function matName() {
var lookupObject = Xrm.Page.getAttribute("new_material");

if (lookupObject != null)
{
    var lookUpObjectValue = lookupObject.getValue();
    if ((lookUpObjectValue != null))
    {
     var lookuptextvalue = lookUpObjectValue[0].keyValues;
     if (lookuptextvalue.name_Value.value) {
     var lookuptextvaluex = lookUpObjectValue[0].keyValues.name_Value.value;
     }
     else if(lookuptextvalue.name.value) {
     var lookuptextvaluex = lookUpObjectValue[0].keyValues.name.value;
     }
     var lookupid = lookUpObjectValue[0].id;

     Xrm.Page.getAttribute("new_matname").setValue(lookuptextvaluex);
    }
    else {
     Xrm.Page.getAttribute("new_matname").setValue();
}
}
}

Thanks Elda.

Aucun commentaire:

Enregistrer un commentaire