函数返回undefined

时间:2016-04-21 20:11:18

标签: javascript

我在文件1中定义了getGlobalOptionSetTextByValue函数。此函数返回一个值。我从文件2调用此函数,但返回值似乎始终设置为undefined。

以下是文件2中的代码:

var X= X|| { __namespace: true };
X.TravelHistory = ( function () {
    //This function will calculate the duration and sent an error message if the duration is greater than 6 months.
    function TravelDuration( fromDate, toDate ) {
        var crtlDate = Xrm.Page.getControl( toDate );
        var toDate = Xrm.Page.getAttribute( toDate ).getValue();
        var fromDate = Xrm.Page.getAttribute( fromDate ).getValue();
        var optionSet = Xrm.Page.getAttribute( "dads_javascriptoptionset" );
        var notification;
        if ( toDate != null && fromDate != null ) {
            var temp1 = new Array();
            temp1 = toDate.split( '/' ); // split the To date with '/'
            var toYear = temp1[0];
            var toMonth = temp1[1];

            var temp2 = new Array();
            temp2 = fromDate.split( '/' ); // split the From date with '/'
            var fromYear = temp2[0];
            var fromMonth = temp2[1];
            //To year have to be less than From year
            if ( toYear < fromYear ) {
                //crtlDate.setNotification( "TO Date needs to be later than the FROM date." );
                notification = X.Common.getGlobalOptionSetTextByValue( 450640028, optionSet );
                crtlDate.setNotification( notification );

            }
        }
    }
    return {
        TravelDuration: function ( fromDate, toDate ) {
            TravelDuration( fromDate, toDate );
        }
    };
})();

以下是文件1中的代码:

var X= X|| { __namespace: true };
X.Common = ( function () {
    var label;
    function getGlobalOptionSetTextByValue( value, optionSetLogicalName ) {
        var globalOptionSet = optionSetLogicalName
        var entityLogicalName = Xrm.Page.data.entity.getEntityName();

        for ( var i = 0; i < globalOptionSet.getOptions().length; i++ ) {
            if ( globalOptionSet.getOptions()[i].value == value ) {
                label = globalOptionSet.getOptions()[i].text;
                break;
            }
        }
        return label;
    }
    return {
        getGlobalOptionSetTextByValue: function(value, optionSetLogicalName) {
            getGlobalOptionSetTextByValue(value, optionSetLogicalName);
        }
    };
})();

1 个答案:

答案 0 :(得分:0)

问题是Xrm.Page.getAttribute( "dads_javascriptoptionset" );返回的对象不包含值为

的条目
{
 id: 450640028,
 text: "....whatever..."
}