I am getting the following error Javascript runtime error: function expected
I am getting the following error Javascript runtime error: function expected
The code works ok until a call a page method.
This is the function that is giving trouble
SetCellValueFromKey = (row, CellName, totalQty);
the function is an another js file
function SetCellValueFromKey(theRow, theKey, setValue) {
theRow.get_cellByColumnKey(theKey).set_value(setValue);
}
here is my page method function
PageMethods.GetSalesOrderInfo(dteStartDate, dteEndDate, ProductsArray, GetSalesOrderInfoCallSuccess, GetSalesOrderInfoCallFailed);
return false;
Here is the GetSalesOrderInfoCallSuccess function
function GetSalesOrderInfoCallSuccess(result) {
var lbActualSales = document.getElementById("<%=lbActualSales.ClientID%>");
var hdnWeekNumOfWeekYear = document.getElementById("<%=hdnWeekNumOfWeekYear.ClientID%>").value;
// Code to handle a Success from 'GetActualSalesInfoCallSuccess'
//if result it not null, parse the data
if (result != null) {
var jsResult = JSON.parse(result);
//clear the Actual Sales list box
var NumRows = lbActualSales.length;
if (NumRows != 0) {
for (var i = NumRows - 1; i >= 0 ; i--) {
//remove the row
lbActualSales.options.remove(i);
}
}
NumRows = jsResult.length;
var optionNum = 0;
if (NumRows > 0) {
for (var i = 0; i < NumRows; i++) {
var dataRow = jsResult[i];
//Add the new data into Actual Sales ListBox
var option = "option" + optionNum;
option = document.createElement("option");
lbActualSales.options.add(option, lbActualSales.options.length);
strRow = [dataRow.SalesOrderId] + "|" + [dataRow.ProductId] + "|" + [dataRow.Quantity] + "|" + [dataRow.Weight] + "|" + [dataRow.UnitPrice] + "|" + [dataRow.TotalPrice] + "|" + [dataRow.ListPrice] + "|" + [dataRow.SalesOrderNum] + "|" + [dataRow.CustomerId] + "|" + [dataRow.DateCreated] + "|" + [dataRow.CustomerName] + "|" + [dataRow.UnitOfSale] + "|" + [dataRow.Product_Name] + "|" + [dataRow.Week] + "|" + [dataRow.OrderType];
option.text = strRow;
option.value = [dataRow.ProductId] + "|" + [dataRow.Week];
optionNum = optionNum + 1;
}
}
var grid = getGrid("<%=wdgSalesForecast.ClientID%>");
var search = "";
var totalQty = 0;
NumRows = lbActualSales.length;
//for each row in grid get the ProductId and the week to search into the listBox
for (var i = 0; i < grid.get_rows().get_length() ; i++) {
var row = grid.get_rows().get_row(i);
var productId = getCellValueFromKey(row, "ProductId");
search = productId;
//loop through the row to change each value for Actual Sales
for (var j = 0; j < row.get_cellCount() ; j++) {
var cell = row.get_cell(j);
var CellName = cell._column._key;
//get the week num and build a string "search"
if (CellName.search("ActAmtWk") > -1) {
var WeekNum = CellName.split("ActAmtWk");
WeekNum = WeekNum.pop();
var weekNumOfYear = parseInt(WeekNum) + parseInt(hdnWeekNumOfWeekYear) - 1;
search = search.concat("|");
search = search.concat(weekNumOfYear);
//loop through the Actual Sales List box and search for the product for the specific week
for (var count = 0; count < NumRows; count++) {
if (search == lbActualSales.options[count].value) {
var splitValues = lbActualSales.options[count].text.split("|");
// Calculate the Qty
totalQty = totalQty + parseInt(splitValues[7]);
}
}
//update the Forecast Grid cell with the New Value
SetCellValueFromKey = (row, CellName, totalQty);
}
//reset my search string and totalQty
search = productId;
totalQty = 0;
}
}
UpdateDemandForecast();
}//end of result test
alert('Data Updated successfully');
}//end of function `
ps. I call others functions from the same js file and I have no problem with.
2 Answers
2
Your line of code is an assignment statement, which is why it's causing you problems:
SetCellValueFromKey = (row, CellName, totalQty);
You've already created the function SetCellValueFromKey(theRow, theKey, setValue)
so to call that function, you should use:
SetCellValueFromKey(theRow, theKey, setValue)
SetCellValueFromKey(row, CellName, totalQty);
No problem at all! Sometimes (ie. regularly) the hardest issues to resolve are the easiest ones. It's really easy to gloss over an obvious mistake in your own code. We've all done it!
– AJC24
Jun 29 at 10:05
Try giving following
SetCellValueFromKey(row, CellName, totalQty);
instead of
SetCellValueFromKey = (row, CellName, totalQty);
SetCellValueFromKey = (row, CellName, totalQty);
Thank you so much ... too long looking at the code could not see this stupid mistake .. I called that function many times in the rest of the code. Sorry waste your time :)
– Lucelli
Jun 29 at 10:02
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thank you so much ... too long looking at the code could not see this stupid mistake .. I called that function many times in the rest of the code. Sorry waste your time :)
– Lucelli
Jun 29 at 10:02