2016-04-21 333 views
-1

我在文件1中定義了getGlobalOptionSetTextByValue函數。該函數返回一個值。我從文件2調用這個函數,但是返回值似乎總是被設置爲undefined。函數返回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

你的代碼不是很容易遵循:-(什麼都沒做什麼? – Tuvia

+0

爲什麼你在2個不同的頁面上有2個功能?它讓我想起了C++ ... – zer00ne

+0

這組javascript文件所採用的路徑並不清楚,因爲您在這兩個文件中都調用了相同的函數。我不知道你究竟從哪裏開始,以及你的計劃在哪裏結束。另外,我會嘗試將'console.log()'放在代碼的一些地方,這樣你就可以準確地找到它出錯的地方,並且變得不確定。 – JoeL

回答

0

的問題是,由Xrm.Page.getAttribute("dads_javascriptoptionset");返回的對象不包含與所述一個條目值如

{ 
id: 450640028, 
text: "....whatever..." 
}