Jquery datatable warning - javascript

I have a jquery editable table.
In code behind there are three actions.
One to load data for datatable
Another to delete data from datatable
And the last one for Save data.
There is nothing special in these actions.
I have The problem with save data. Data are saved correctly to database and then there is redirection to load data to datable again.
When data are saved correctly do database, there is redirection which load new data to datatable and then i get this warning:
DataTables warning: table id=myDataTable - Requested unknown parameter '0' for row 8. For more information about this error, please see http://datatables.net/tn/4
I have looked this error on that page and i can not still find solution for this bug.
Interesting is when i get this error and i refresh page with datatable this time data are loaded correctly.
I do not know what is going on.
Please help
Here are two problematic actions
[HttpGet]
public ActionResult TesotwanieTabelki(int promotionId)
{
marketPromocji.Areas.DELIVER.Models.PromotionsProductsViewModel promotionProductsViewModelItem =
new marketPromocji.Areas.DELIVER.Models.PromotionsProductsViewModel();
promotionProductsViewModelItem.productDetails =
new List<marketPromocji.Areas.DELIVER.Models.ProductDetails>();
marketPromocji.Models.promocje promocje = unitOfWork.PromocjeRepository.GetByID(promotionId);
aspnet_Users produktyWDanejPromocji=promocje.promocje_produkty.Select(x => x.produkty).First().aspnet_Users; //czyje produkty w danej promocji
ICollection<produkty> produkty = unitOfWork.ProduktyRepository.Get().Where(x => x.aspnet_Users.UserId== produktyWDanejPromocji.UserId).ToList();
List<SelectListItem> selectList=new List<SelectListItem>();
foreach (produkty p in produkty)
{
selectList.Add(new SelectListItem { Text = p.nazwa, Value = p.id.ToString()});
}
promotionProductsViewModelItem.selectList = selectList;
promotionProductsViewModelItem.data_start = promocje.data_start;
promotionProductsViewModelItem.data_koniec = promocje.data_koniec;
promotionProductsViewModelItem.czy_zielony_koszyk = promocje.czy_zielony_koszyk;
promotionProductsViewModelItem.id = promocje.id;
promotionProductsViewModelItem.poziom_dostepnosci = promocje.poziom_dostepnosci;
promotionProductsViewModelItem.wynagrodzenie = promocje.wynagrodzenie;
if (promocje.sposob_wynagrodzenia != null)
{
promotionProductsViewModelItem.sposobWynagrodzenia = promocje.sposob_wynagrodzenia;
}
else
{
promotionProductsViewModelItem.sposobWynagrodzenia = "";
}
ICollection<marketPromocji.Models.promocje_produkty> promocje_produkty = unitOfWork.PromocjeProduktyRepository.Get().Where(x => x.ref_promocja == promotionId).ToList();
foreach (marketPromocji.Models.promocje_produkty item in promocje_produkty)
{
promotionProductsViewModelItem.productDetails.Add(new marketPromocji.Areas.DELIVER.Models.ProductDetails()
{
productId = item.produkty.id,
cena_brutto = item.cena_brutto,
cena_brutto_dla_sklepu = item.cena_brutto_dla_sklepu,
cena_netto = item.cena_netto,
cena_netto_dla_sklepu = item.cena_netto_dla_sklepu,
nazwa = item.produkty.nazwa,
url_obrazka = item.produkty.url_obrazka
});
}
Session[User.Identity.Name] = promotionProductsViewModelItem; //this session is used for datatable update action
return View(promotionProductsViewModelItem);
}
[HttpPost]
public ActionResult AddData(FormCollection formCollection)
{
int promotionId = Convert.ToInt32(formCollection.Get("promotionId"));
string addedProductId = formCollection.Get("Produkty");
int productId = Convert.ToInt32(addedProductId);
marketPromocji.Areas.DELIVER.Models.PromotionsProductsViewModel promotionsProductsViewModel =
(marketPromocji.Areas.DELIVER.Models.PromotionsProductsViewModel)Session[User.Identity.Name];
produkty produkt = new produkty();
produkt = unitOfWork.ProduktyRepository.GetByID(productId);
promocje_produkty promocjeProdukty = new promocje_produkty();
promocjeProdukty.cena_brutto = Convert.ToDecimal(formCollection.Get("cenaZakupuNetto")); //tutaj to jeszcze musze sprawdzic czy to w odpowiedniej kolejnosci jest;/
promocjeProdukty.cena_brutto_dla_sklepu = Convert.ToDecimal(formCollection.Get("cenaZakupuBrutto"));
promocjeProdukty.cena_netto = Convert.ToDecimal(formCollection.Get("cenaSprzedazyNetto"));
promocjeProdukty.cena_netto_dla_sklepu = Convert.ToDecimal(formCollection.Get("cenaSprzedazyBrutto"));
string zielonyKoszyk = formCollection.Get("zielonyKoszyk");
if(zielonyKoszyk==null)
{
promocjeProdukty.czy_zielony_koszyk = false;
}
else
{
promocjeProdukty.czy_zielony_koszyk = true;
}
promocjeProdukty.ref_produkt = productId;
promocjeProdukty.ref_promocja = promotionId;
try
{
unitOfWork.PromocjeProduktyRepository.Insert(promocjeProdukty);
unitOfWork.Save();
}
catch(Exception ex)
{
}
return RedirectToAction("TesotwanieTabelki", new { promotionId=promotionId});
}

Related

functionality is not working for newly created menu

I'm working on creating the Link menu on the Oxygen Web-Author, there is already having two menu's called "ulink" and "uri". When I include the third menu called xref, the functionality of xref is not working fine, It's taking "ulink" functionality in the oxygen framework.js.
var insertWebLinkActionId =
sync.docbook.DocbookExtension.prototype.version == 5 ? "insert.web.link" : "insert.web.ulink";
var originalInsertWebLinkAction = actionsManager.getActionById(insertWebLinkActionId);
if(originalInsertWebLinkAction) {
var webLinkOperationClass = sync.docbook.DocbookExtension.prototype.version == 5 ?
"ro.sync.ecss.extensions.docbook.link.InsertExternalLinkOperation" :
"ro.sync.ecss.extensions.docbook.link.InsertULink";
var insertWebLinkAction = new sync.actions.InsertWebLink(
originalInsertWebLinkAction,
webLinkOperationClass,
editor,
'url_value');
actionsManager.registerAction(insertWebLinkActionId, insertWebLinkAction);
}
Here they already inserted menu by using the above code, in that insert.web.link and insert.web.ulink represent the corresponding menu from the translation.xml
<key type="action" value="insert.web.ulink">
<comment>Insert Link action name.</comment>
<val lang="en_US">Web Link (ulink)...</val>
</key>
...
<key type="action" value="insert.cross.reference.xref">
<comment>Insert Link action name.</comment>
<val lang="en_US">Cross reference (xref)...</val>
</key>
So I want to insert the Xref menu to the javascript, the Xref menu and class path represent insert.cross.reference.xref and
ro.sync.ecss.extensions.docbook.link.InsertXrefOperation correspondingly.
You can implement your own version of the "Insert Cross Reference (xref)" action in your DocBook framework extension. To do this you need to:
Create a custom action that prompts the user to choose the destination file and the ID of the target element. The code for this action needs to be added in the "web" folder of you framework in a new JS file. You can find below a minimal working example:
var DocBookCrossRefXrefAction = function (editor) {
sync.actions.AbstractAction.call(this);
this.editor = editor;
this.xrefTargetsDialog = null;
};
DocBookCrossRefXrefAction.prototype =
Object.create(sync.actions.AbstractAction.prototype);
DocBookCrossRefXrefAction.prototype.constructor = DocBookCrossRefXrefAction;
DocBookCrossRefXrefAction.prototype.getDisplayName = function () {
return 'Insert cross reference (xref)';
};
DocBookCrossRefXrefAction.prototype.actionPerformed = function (callback) {
// This callback might have to be called at a later point, so save it until then.
this.callback = callback || function () {};
var chooser = workspace.getUrlChooser();
var context = new sync.api.UrlChooser.Context(sync.api.UrlChooser.Type.EXTERNAL_REF);
chooser.chooseUrl(context, this.showXrefTargetChooser.bind(this),
sync.api.UrlChooser.Purpose.CHOOSE);
};
DocBookCrossRefXrefAction.prototype.showXrefTargetChooser = function (url) {
if (url) {
// Create a dialog to display all targets, so the user can select one to insert
// cross reference.
this.xrefTargetsDialog = this.createXrefTargetsDialog();
this.populateXrefTargetsDialog(url);
this.xrefTargetsDialog.onSelect(function (key, e) {
if (key === 'ok') {
e.preventDefault();
this.xrefTargetChosen();
} else {
this.callback();
}
}.bind(this));
this.xrefTargetsDialog.show();
} else {
this.callback();
}
};
DocBookCrossRefXrefAction.prototype.createXrefTargetsDialog = function () {
var dialog = workspace.createDialog();
dialog.setTitle('Choose cross reference');
dialog.setButtonConfiguration(sync.api.Dialog.ButtonConfiguration.OK_CANCEL);
dialog.setPreferredSize(700, 500);
dialog.setResizable(true);
return dialog;
};
DocBookCrossRefXrefAction.prototype.populateXrefTargetsDialog = function (url) {
this.editor.getActionsManager()
.invokeOperation('ro.sync.servlet.operation.FindXrefTargetsOperation', {url: url})
.then(function(str) { return JSON.parse(str);})
.then(this.xrefTargetsReceived.bind(this))
};
DocBookCrossRefXrefAction.prototype.xrefTargetsReceived = function (targets) {
var container = this.xrefTargetsDialog.getElement();
if (!targets || !targets.length) {
container.textContent = 'No cross reference targets found in the chosen file';
} else {
for (var i = 0; i < targets.length; i++) {
var radio = document.createElement('input');
radio.name = 'docbook-ref-table-radio';
radio.type = 'radio';
radio.dataset.id = targets[i].id;
var label = document.createElement('label');
label.style = 'display: block';
label.appendChild(radio);
label.appendChild(document.createTextNode(targets[i].nodeName + ' (#' +
targets[i].id + ') - ' + targets[i].content.substring(0, 50)));
container.appendChild(label);
}
}
};
DocBookCrossRefXrefAction.prototype.xrefTargetChosen = function() {
var targetRadio = this.xrefTargetsDialog.getElement().querySelector(
'input[name="docbook-ref-table-radio"]:checked');
if (targetRadio) {
this.editor.getActionsManager().invokeOperation('InsertFragmentOperation',
{fragment: '<xref linkend="' + targetRadio.dataset.id + '"/>'})
.then(this.xrefInserted.bind(this));
}
};
DocBookCrossRefXrefAction.prototype.xrefInserted = function () {
this.xrefTargetsDialog && this.xrefTargetsDialog.dispose();
this.callback();
};
DocBookCrossRefXrefAction.prototype.dispose = function() {
this.xrefTargetsDialog && this.xrefTargetsDialog.dispose();
};
goog.events.listen(workspace, sync.api.Workspace.EventType.EDITOR_LOADED, function(e) {
var editor = e.editor;
goog.events.listen(editor, sync.api.Editor.EventTypes.ACTIONS_LOADED, function(e) {
editor.getActionsManager().registerAction('insert.cross.reference.xref',
new DocBookCrossRefXrefAction(editor));
});
});
This action uses a server-side AuthorOperationWithResult to collect xref targets from the file chosen by the user. You can find below the code of this Java operation:
package ro.sync.servlet.operation;
import java.net.URL;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import org.codehaus.jackson.map.ObjectMapper;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import ro.sync.basic.util.URLUtil;
import ro.sync.ecss.extensions.api.ArgumentsMap;
import ro.sync.ecss.extensions.api.AuthorOperationException;
import ro.sync.ecss.extensions.api.webapp.AuthorDocumentModel;
import ro.sync.ecss.extensions.api.webapp.AuthorOperationWithResult;
import ro.sync.ecss.extensions.api.webapp.WebappRestSafe;
import ro.sync.xml.parser.ParserCreator;
#WebappRestSafe
public class FindXrefTargetsOperation extends AuthorOperationWithResult {
#Override
public String doOperation(AuthorDocumentModel model, ArgumentsMap args)
throws AuthorOperationException {
String urlString = (String) args.getArgumentValue("url");
try {
URL url = URLUtil.addAuthenticationInfo(
model.getAuthorAccess().getEditorAccess().getEditorLocation(),
new URL(urlString));
InputSource is = new InputSource(url.toString());
DocumentBuilder docBuilder = ParserCreator.newSchemaAwareDocumentBuilder();
Document document = docBuilder.parse(is);
ArrayList<XrefTarget> xrefTargets = new ArrayList<>();
gatherXrefTargets(document, xrefTargets);
return new ObjectMapper().writeValueAsString(xrefTargets);
} catch (Exception e) {
throw new AuthorOperationException(e.getMessage(), e);
}
}
public static class XrefTarget {
public final String id;
public final String nodeName;
public final String content;
public XrefTarget(Element elem) {
this.id = getIDValue(elem);
this.nodeName = elem.getTagName();
this.content = elem.getTextContent();
}
}
private static void gatherXrefTargets(Node node, ArrayList<XrefTarget> xrefTargets) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element elem = (Element) node;
if (getIDValue(elem) != null) {
xrefTargets.add(new XrefTarget(elem));
}
}
NodeList childNodes = node.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
gatherXrefTargets(childNodes.item(i), xrefTargets);
}
}
public static String getIDValue(Element elem) {
NamedNodeMap attributes = elem.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
Attr attribute = (Attr)attributes.item(i);
// There are some ID attributes defined as such in the schema file.
if (attribute.isId() || "xml:id".equals(attribute.getName()) ||
"id".equals(attribute.getName())) {
return attribute.getValue();
}
}
return null;
}
}
You need to compile this Java class and add it as a JAR file in the classpath of your framework. More details here .

Displaying data from a query using a drop down list selection mvc

I am sort of lost on the coding part of this problem. I have a MVC application, and I am trying to populate a queries Where clause as the selected value from my drop down list. Also, I am populating the drop down list from a query in the database. For example:
SELECT db.ID FROM Database db where ID = 1232
Instead of that, I want to do something like this...
SELECT db.ID FROM Database db where ID = "SelectedValue from Dropdownlist"
Model Class:
public string ID {get; set;}
public string Summary{get; set;}
public int Estimate {get; set;}
public List<Hello> getIDs()
{
var que = (from wre in db.Table
select new Hello{
ID = wre.ID
}).toList();
}
Controller class:
public ActionResult Index(string? IDParam)
{
var model = test.getStuff();
var que = (from wre in db.View
where wre.ID == IDParam //Operator '==' cannot be applied to operands of type 'string' and 'string?'
select new Hello
{
ID = wre.ID
Summary = wre.Summary,
Estimate = wre.Estimate
}).toList();
if (IDParam!= null & IDParam.HasValue)
{
model = model.Where(x => x.ID == IDParam); //Operator '==' cannot be applied to operands of type 'string' and 'string?'
}
return View(model);
}
View Class:
#Html.DropDownList("ID", ViewBag.Releases as SelectList, "ID", new {#id="rel" })
<table>
<th>#Html.DisplayNameFor(model => model.ID)</th>
<th>#Html.DisplayNameFor(model => model.Summary)</th>
<th>#Html.DisplayNameFor(model => model.Estimate)</th>
</table>
<script>
$("#rel").change(function () {
var selectedId = this.val();
location.href = '#Url.Action("Index", "SampleController", new {selectedId="_selectedId"})'.Replace("_selectedId",selectedId);
});
</script>
This works perfectly fine, but now, I am lost on the coding aspect of it. I can see the alert every time I change the ID from the drop down list. However, there is no change in the data being displayed (I know I am missing a lot). If anyone can help me out here, that would be great, thank you!
1) Try adding where clause in Linq
where wre.ID == IDParam
2) Change que to instance of your class and get firstOrDefault instead of List
3) Try passing instance of your class as a model in view
return View(test);
1- You need to get changed Id as below :
$("#rel").change(function () {
// alert("Changed");
var selectedId =this.value;
});
2- If you want to reload your page then you need to set a parametre to your [HttpGet] Method :
public ActionResult Index(int? selectedId) // selectedId
{
var que = (from wre in db.View
select new Hello
{
ID = IDParam
Summary = wre.Summary,
Estimate = wre.Estimate
}).toList();
ViewBag.Releases = new SelectList(test.getIDs(), "", "ID");
var model = test.getStuff();
if(selectedId!=null && selectedId.HasValue)
{
// do some stuff with your selectedId
// if working method is test.getStuff(), then maybe you can use like code below:
model = model.Where(x=> x.Id==selectedId);
}
return View(model);
}
and in your View:
$("#rel").change(function () {
// alert("Changed");
var selectedId =this.value;
location.href = '#Url.Action("Index", "YourController", new {selectedId="_selectedId"})'.Replace("_selectedId",selectedId);
});
3- If you dont want to reload page then you need to use Ajaxrequest, You must create a new method for get data by selectedId,
// Your view.
$("#rel").change(function () {
// alert("Changed");
var selectedId =this.value;
$.ajax({
method: "POST",
url: "'#Url.Action("GetDataBySelectedId","YourController")'",
data: { selectedId: selectedId }
})
.done(function( data) {
// Delete your table, and fill table with your data with jquery.
});
});
// your Controller:
[HttpPost]
public JsonResult GetDataBySelectedId(int? selectedId)
{
// Do some stuff for get your data.
var data = yourData.Where(x=> x.Id = selectedId.Value);
return Json(data);
}

MVC, how get model property from response viewModel

I am implementing "show more posts" in my blogs list following
this example but I want to make a change and switch from using ViewData to ViewModel.
This the relevant code:
private void AddMoreUrlToViewData(int entryCount)
{
ViewData["ShowMore "] = Url.Action("Index", "Messaggi", new { entryCount = entryCount + defaultEntryCount });
}
that I switch to
ViewModel.ShowMore = Url.Action("Index", "Messaggi", new { entryCount = entryCount + defaultEntryCount });
the Index action of the example:
public ActionResult Index(int? entryCount)
{
if (!entryCount.HasValue)
entryCount = defaultEntryCount;
int totalItems;
if(Request.IsAjaxRequest())
{
int page = entryCount.Value / defaultEntryCount;
//Retrieve the page specified by the page variable with a page size o defaultEntryCount
IEnumerable<Entry> pagedEntries = GetLatestEntries(page, defaultEntryCount, out totalItems);
if(entryCount < totalItems)
AddMoreUrlToViewData(entryCount.Value);
return View("EntryTeaserList", pagedEntries);
}
//Retrieve the first page with a page size of entryCount
IEnumerable<Entry> entries = GetLatestEntries(1, entryCount.Value, out totalItems);
if (entryCount < totalItems)
AddMoreUrlToViewData(entryCount.Value);
return View(entries);
}
Here I add a lot of code to load the post from the db, the only code I think is relevant is that I swtich return View("EntryTeaserList", pagedEntries); to return View(myViewModel); after setting BlogsList and ShowMore property.
But my problem is in the javascript command:
$(function() {
addMoreLinkBehaviour();
});
function addMoreLinkBehaviour() {
$('#entryTeaserList #moreLink').live("click", function() {
$(this).html("<img src='/images/ajax-loader.gif' />");
$.get($(this).attr("href"), function(response) {
$('#entryTeaserList ol').append($("ol", response).html());
$('#entryTeaserList #ShowMore').replaceWith($("#ShowMore", response));
});
return false;
});
}
where
$('#entryTeaserList #ShowMore').replaceWith($("#ShowMore", response));
to take ViewData property and use it to replace the link.
How can I read the ViewModel Property instead?

How to pass postData using ng-href

I have the following scenario. I am doing an excel export. It works fine when I use ng-href by passing just one ID in query string. But now I have multiple ID's to pass, So I am using ng-click in HTML and $http.POST that passes postData to the server as shown below. The problem is if I use ng-click and call $http.post, it gets the required data but it wont create the excel document. I think it is because I am not using ng-href, but cant figure out how to fix it. Any help would be greatly appreciated.
HTML:
<div id="transmission-buttons" data-ng-show="resultsReturned">
<!--<a ng-href="../ExcelDownload/ExcelDownload.aspx?workListID={{selectedExportWorkListID}}" class="btn btn-info pull-right" target="_blank"><span class="glyphicon glyphicon-export"></span>Export to Excel</a>-->
<a class="btn btn-info pull-right" href="" ng-click="getWorklistExportData($event)" target="_blank"><span class="glyphicon glyphicon-export"></span>Export to Excel</a>
</div>
Controller.JS:
$scope.getWorklistExportData = function (e) {
rest.post('../ExcelDownload/ExcelDownload.aspx', $scope.selectedWorkListIDs).success(function (resp) {
var successResp = resp;
e.preventDefault();
}).error(function (resp) {
var errResp = resp;
});
}
aspx.cs:
public partial class ExcelDownload_ExcelDownload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var sr = new StreamReader(Request.InputStream);
var stream = sr.ReadToEnd();
CreateExcel(stream);
//CreateExcel(Convert.ToInt32(Request.QueryString["workListID"]));
//CreateExcel(823);
}
}
private void CreateExcel(string cbrIdList)
{
var client = new RestClient(ConfigurationManager.AppSettings["TIBCOServer"]);
string url = ConfigurationManager.AppSettings["ExportWorklistCBRS"];
//url = url.Replace("{workListID}", workListID.ToString());
var request = CreateStandardRestRequest(url, Method.POST);
request.RootElement = "WorkListDetailExport";
request.AddParameter("CBR_ID", cbrIdList, ParameterType.RequestBody);
var queryResult = client.Execute<List<CBRSRecord>>(request);
var queryResult2 = client.Execute(request);
DataTable tbl = ToDataTable<CBRSRecord>(queryResult.Data);
tbl = FormatColumnNames(tbl);
// DataTable tbl = new DataTable();
using (ExcelPackage pck = new ExcelPackage())
{
//Create the worksheet
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Worklist");
//Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
ws.Cells["A1"].LoadFromDataTable(tbl, true);
for (int x = 1; x < 50; x++)
{
ws.Column(x).AutoFit();
}
using (ExcelRange rng = ws.Cells["A1:AB1"])
{
rng.Style.Font.Bold = true;
}
//Write it back to the client
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment; filename=WorkList" + DateTime.Now.ToLongTimeString() + ".xlsx");
Response.BinaryWrite(pck.GetAsByteArray());
Response.End();
}
}

xpages JSON-RPC Service handling response from callback funciton

I have a slickgrid screen (on regular Domino form) wherein user can select and update some documents. I needed to show a pop-up displaying status of every selected document so I created an XPage. In my XPage I am looping through selected documents array (json) and call an RPC method for every document. Code to call RPC method is in a button which is clicked on onClientLoad event of XPAGE. RPC is working fine because documents are being updated as desired. Earlier I had RPC return HTML code for row () which was being appended to HTML table. It works in Firefox but not in IE. Now I am trying to append rows using Dojo but that’s not working either.
Here is my Javascript code on button click.
var reassign = window.opener.document.getElementById("ResUsera").innerHTML;
var arr = new Array();
var grid = window.opener.gGrid;
var selRows = grid.getSelectedRows();
for (k=0;k<selRows.length;k++)
{
arr.push(grid.getDataItem(selRows[k]));
}
var tab = dojo.byId("view:_id1:resTable");
while (arr.length > 0)
{
var fldList = new Array();
var ukey;
var db;
var reqStatusArr = new Array();
var docType;
var docno;
ukey = arr[0].ukey;
db = arr[0].docdb;
docType = arr[0].doctypeonly;
docno = arr[0].docnum;
fldList.push(arr[0].fldIndex);
reqStatusArr.push(arr[0].reqstatusonly);
arr.splice(0,1)
for (i=0;i < arr.length && arr.length>0;i++)
{
if ((ukey == arr[i].ukey) && (db == arr[i].docdb))
{
fldList.push(arr[i].fldIndex);
reqStatusArr.push(arr[i].reqstatusonly);
arr.splice(i,1);
i--;
}
}
console.log(ukey+" - "+db+" - "+docno+" - "+docType);
var rmcall = faUpdate.updateAssignments(db,ukey,fldList,reassign);
rmcall.addCallback(function(response)
{
require(["dojo/html","dojo/dom","dojo/domReady!"],function(html,dom)
{
var tbdy = dom.byId("view:_id1:resTable").getElementsByTagName("tbody");
html.set(tbdy,
tbdy.innerHTML+"<tr>"+
"<td>"+docType+"</td>"+
"<td>"+docno+"</td>"+
"<td>"+reqStatusArr.join("</br>")+"</td>"+
"<td>"+response+"</td></tr>"
);
});
});
}
dojo.byId("view:_id1:resTable").style.display="inline";
dojo.byId("idLoad").style.display="none";
RPC Service Code
<xe:jsonRpcService
id="jsonRpcService2"
serviceName="faUpdate">
<xe:this.methods>
<xe:remoteMethod name="updateAssignments">
<xe:this.arguments>
<xe:remoteMethodArg
name="dbPth"
type="string">
</xe:remoteMethodArg>
<xe:remoteMethodArg
name="uniquekey"
type="string">
</xe:remoteMethodArg>
<xe:remoteMethodArg
name="fieldList"
type="list">
</xe:remoteMethodArg>
<xe:remoteMethodArg
name="reassignee"
type="string">
</xe:remoteMethodArg>
</xe:this.arguments>
<xe:this.script><![CDATA[print ("starting update assignments from future assignments page");
var db:NotesDatabase = null;
var vw:NotesView = null;
var doc:NotesDocument = null;
try{
db=session.getDatabase("",dbPth);
if (null!= db){
print(db.getFileName());
vw = db.getView("DocUniqueKey");
if (null!=vw){
print ("got the view");
doc = vw.getDocumentByKey(uniquekey);
if (null!=doc)
{
//check if the document is not locked
if (doc.getItemValueString("DocLockUser")=="")
{
print ("Got the document");
for (i=0;i<fieldList.length;i++)
{
print (fieldList[i]);
doc.replaceItemValue(fieldList[i],reassignee);
}
doc.save(true);
return "SUCCESS";
}
else
{
return "FAIL - document locked by "+session.createName(doc.getItemValueString("DocLockUser")).getCommon();
}
}
else
{
return "FAIL - Contact IT Deptt - Code: 0";
}
}
else
{
return "FAIL - Contact IT Deptt - Code: 1";
}
}
else
{
return "FAIL - Contact IT Deptt - Code: 2";
}
}
catch(e){
print ("Exception occured --> "+ e.toString());
return "FAIL - Contact IT Deptt - Code: 3";
}
finally{
if (null!=doc){
doc.recycle();
vw.recycle();
db.recycle();
}
}]]></xe:this.script>
</xe:remoteMethod>
</xe:this.methods>
</xe:jsonRpcService>
Thanks in advance
I have resolved this issue. First, CSJS variables were not reliably set in callback function so I made RPC return the HTML string I wanted. Second was my mistake in CSJS. I was trying to fetch tbody from table using
var tbdy = dom.byId("view:_id1:resTable").getElementsByTagName("tbody");
where as it returns an array so it should have been
var tbdy = dom.byId("view:_id1:resTable").getElementsByTagName**("tbody")[0]**;
also I moved tbody above while loop. I can post entire code if anyone is interested!!

Categories

Resources