currentRecord.setText defualting to last value - netsuite

I have a custom suitelet which I am trying to set the values of a couple select fields on a client script.
I have a list of sales reps which is generated by a search in the suitlet.
var salesrep = form.addField({
id : 'custpage_salesrep',
label : 'Sales Rep',
type : serverWidget.FieldType.SELECT,
container : 'reportcriteria'
});
salesrep.addSelectOption({
value : 0,
text : '-All-'
});
getSalesrepSearch().run().each(function(result){
salesrep.addSelectOption({
value : result,
text : result.getValue('firstname') + ' ' + result.getValue('lastname')
});
salesrepArray.push([result.getValue('firstname') + ' ' +
result.getValue('lastname'),result.id])
return true
})
on the client script I am trying to set the text value with the following
recObj.setText({
fieldId: 'custpage_salesrep',
text: dataSalesRep
});
For some reason no matter what I do the field is set to the last name/ value on the list.
I have confirmed that the name is correct (console log shows the correct name)
I have hard coded the correct text and received the same result.
This is the only field having an issue and the only difference is that the list is populated from the search. I am not sure if that is affecting the outcome.

After some additional debugging I discovered that by using the result for value, I was actually setting the value to the whole result object. So instead I added a counter and that solved my problem.
var i = 0
getSalesrepSearch().run().each(function(result){
salesrep.addSelectOption({
value : i,
text : result.getValue('firstname') + ' ' + result.getValue('lastname')
});
salesrepArray.push([result.getValue('firstname') + ' ' + result.getValue('lastname'),result.id])
i++
return true
})

Related

How can I match exact text in a particular column and output the entire row of information?

I have been attempting to create a Telegram bot that searches a preexisting database and outputs information based on search query, essentially I want the bot to just receive a text via Telegram that contains an invoice number and output all relevant information regarding that order (The entire row of information).
Since I am dealing with invoice numbers and tracking numbers, sometimes the bot is exporting incorrect information given the current script is not matching exact text or a specific column.
For instance, rather than searching and finding invoice number it picks up a partial match of tracking number and outputs the wrong information.
I would like to set it up to search a specific column, ie. Column 3 - "Invoice #" and then output the entire row of information.
Thanks in advance!
I have been working in Google App Script:
var token = "";
var telegramUrl = "https://api.telegram.org/bot" + token;
var webAppUrl = "";
var ssId = "";
function getMe() {
var url = telegramUrl + "/getMe";
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
}
function setWebhook() {
var url = telegramUrl + "/setWebhook?url=" + webAppUrl;
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
}
function sendText(id,text) {
var url = telegramUrl + "/sendMessage?chat_id=" + id + "&text=" + text;
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
}
function doGet(e) {
return HtmlService.createHtmlOutput("Hi there");
}
function doPost(e) {
var data = JSON.parse(e.postData.contents);
var text = data.message.text;
var id = data.message.chat.id;
var name = data.message.chat.first_name + " " + data.message.chat.last_name;
var answer = "Hi " + name + ", please enter invoice number.";
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Orders");
var search_string = text
var textFinder = sheet.createTextFinder(search_string)
var search_row = textFinder.findNext().getRow();
var value = SpreadsheetApp.getActiveSheet().getRange("F"+search_row).getValues();
var value_a = SpreadsheetApp.getActiveSheet().getRange("G"+search_row).getValues();
sendText(id,value+" "+ value_a)
}
You want to find rows where the content in column 3 is exactly equal to your variable "text"
Modify your function doPost as following:
function doPost(e) {
var data = JSON.parse(e.postData.contents);
var text = data.message.text;
var id = data.message.chat.id;
var name = data.message.chat.first_name + " " + data.message.chat.last_name;
var answer = "Hi " + name + ", please enter invoice number.";
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Orders");
var range = sheet.getRange(1,1, sheet.getLastRow(), sheet.getLastColumn());
var values = range.getValues();
for (var i=0; i< values.length; i++){
var column3Value = values[i][2];
if(column3Value == text){
var rowValues = values[i].toString();
sendText(id,rowValues)
}
}
}
Explanations
The for loop iterates through all rows and compares the values in column 3 (array element[2] against the value of text
The operator == makes sure that only exact matches are found (indexOf() would also retrieve partial matches)
In case a match is found, the values from the whole row are converted to a comma separated string with toString() (You can procced the values differntly if desired)
Every row with a match will be sent to the function sendText() (you could alternatively push all rows with matches into an array / string and call sendText() only once, after exiting the for loop
I hope this answer helps you to solve your problem and adapt the provided code snippet to your needs!
I would look for a specific column where the order number is stored.
I`m not sure if it is the best way from performance side, but I think it should work.
function orderInformation(orderNumber){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Orders");
//Gets last row in Orders sheet
var lastRow = sheet.getLastRow();
//Here you can change column where is order number stored
var orderNumberRange = sheet.getRange("A1:A" + lastRow);
//Gets all order number values
var orderNumbers = orderNumberRange.getValues();
//You can use indexOf to find which row has information about requested order
var orderLocation = orderNumbers.indexOf(orderNumber);
//Now get row with order data, lets suppose that your order information is from column A to Z
var orderData = sheet.getRange("A" + (orderLocation + 1) + ":Z" + (orderLocation + 1)).getValues();
//Now you have all data in array, where you can loop through and generate response text for a customer.
}
Sorry, I have not tested it, at the moment I don`t have time to make a test sheet, but this is the way I would do it and I think it should work.
I will test it maybe later when I will be able to make a test sheet.

Add Column when using rowFormatter (Cheese Example)

I feel I am missing something simple... The cheese example of how to use the rowFormatter is exactly how I want to implement something, except I'd like to add various additional columns...
I've noted the warning it is important to include only one column in your column definition array to ensure the table renders correctly, however it is exactly what I want to do.
So I tried adding another column to the table constructor which added a column heading but no data.
What an I missing? Surely this is a common use case?
Use the formatter option as apposed to the rowFormatter - which overwrites the entire rows contents.
Based on the printIcon and cheese examples in the Tabulator docs, construct a column formatter, but pass the row as apposed to the cell.
Then its just a matter of constructing the html table as per the cheese example, but return the table, don't append to the element.
My Test Example:
//Generate details
var details = function(row, formatterParams){ //plain text value
var element = row.getElement(),
data = row.getData(),
width = element.outerWidth(),
table;
//define a table layout structure and set width of row
table = $("<table style='width:" + (width - 18) + "px;'><tr></tr></table>");
//add image on left of row
$("tr", table).append("<td><img src='./img/teams/small-60x80/55015.png'></td>");
//add row data on right hand side
$("tr", table).append("<td><div><strong>Type:</strong> " + data.type + "</div><div><strong>Age:</strong> " + data.age + "</div><div><strong>Rind:</strong> " + data.rind + "</div><div><strong>Colour:</strong> " + data.color + "</div></td>");
//append newly formatted contents to the row
//element.append(table);
return table;
//return "<image src='./img/teams/small-60x80/55015.png'>";
};
//define Tabulator
$("#example-table").tabulator({
height:"600px",
layout:"fitColumns",
resizableColumns:false,
columns:[
{formatter:details},
{title:"Cheese", field:"type", sorter:"string"},
{title:"Something Else", field:"blah", sorter:"string"},
],
})

Access field in a column in a Lotus Notes view

In Lotus Notes, I have view which has got a column say PolicyNum. Requirement is while double clicking on the document to open, which will open the attachment in the form in the view, it has to be validated against a computed field say SecureDoc which contains either Yes or No.
For client version this is easy as in the queryopen in the form it is validated and exited if the condition doesn't meet with proper messagebox.
But for the web version the column is appeared as a link and the messagebox has to appeared as alertbox in JS. In the PolicyNum column I have tried to use #GetField("SecureDoc") which will get the value of the field for that particular document.
Column Formula:
furl:="javascript:alert('Document not available');return false";
OpenDisp:="[" + PolicyNumber + "]";
secDoc:=#GetField("SecureDoc");
#If(att = "" ; OpenDoc ;secDoc="Yes";OpenDisp;OpenAttach)
Here OpenDoc and OpenAttach are different string which will open the document and attachment respectively depending on the att, which checks for the attachment.#GetField("SecureDoc") return "". So if I write #If(att = "" ; OpenDoc ;secDoc="";OpenDisp;OpenAttach) it is showing the alert box and is working fine.
So the requirement is to get the handle of the field value for the particular doc which is to be clicked on web and check for the condition.
Also webqueryopen is not working..
Note: On opening the document it is opening the attachment in the form and not the form itself.
Column Value :
view := "0";
att := #AttachmentNames;
WebName := #WebDbName ;
url := "'/" + WebName + "/" + view + "/" + #Text(#DocumentUniqueID) + "/$File/" + att + "?OpenElement'";
url := "window.open(" + url + ");" ;
url := #Implode(url; ";");
url := "javascript:" + url + " return false;\" href=\"javascript:void(0);";
furl:="javascript:alert('Document not available');return false";
OpenAttach := "[<TABLE><TR><TD NOWRAP><a target=_blank onClick=\"" + url + "\">" + PolicyNumber + "</a></TD></TR></TABLE>]";
OpenDoc := "[<TABLE><TR><TD NOWRAP>" + PolicyNumber + "</TD></TR></TABLE>]";
OpenDisp:="[<TABLE><TR><TD NOWRAP><a target=_blank onClick=\"" + furl + "\">" + PolicyNumber + "</a></TD></TR></TABLE>]";
secDoc:=#GetField("prevSecDoc");
#If(att = "" ; OpenDoc ;secDoc="Yes";OpenDisp;OpenAttach)
I have tried with both #If(att = "" ; OpenDoc ;secDoc="Yes";OpenDisp;OpenAttach) and #If(att = "" ; OpenDoc ;prevSecDoc="Yes";OpenDisp;OpenAttach) but it is not getting the value as "Yes". Though when I open the document through URL giving the docid it ha the value as "Yes"
Quick back to basics : a document is a record in a database, a form is, well, a form, which determines how data are input by the user and controls display.
Allow me to rephrase your question. If the document contains a field named "SecureDoc", and if said field holds the value "NO", then a click on the link must not open the document and present the user with a JavaScript alert.
One could question why display the document in the view in the first place, and then why have a link with no other effect than telling it has no effect.
OK, not my place to question the requirements.
My suggestion would be that the content of the column displayed for web access be a computed hyperlink :
href := #If( SecureDoc = "NO";
"javascript:alert('nope')";
"normal url for opening the doc"
);
"" + "the title of the doc or whatever" + ""

How to get the row and column count in an excel using nighwatch js?

I am a begginer in nightwatch js. We are in a process of creating an end to end framework using nightwatch. So for the data retrieval part we are facing difficulties to get the row and column count in an excel and parsing through the data. We did have a look into the exceljs and xlsx module but could not get any methods for that. It will be a great help if someone can share a code to get the row and column count.
var inboundWorkbook = new Excel.Workbook();
inboundWorkbook.xlsx.readFile(req.file.path).then(function() {
var inboundWorksheet = inboundWorkbook.getWorksheet(1); //or give name of the sheet
console.log('------------- actualRowCount: ' + inboundWorksheet.actualRowCount);
console.log('------------ rowCount: ' + inboundWorksheet.rowCount);
console.log('------------ columnCount: ' + inboundWorksheet. columnCount);
inboundWorksheet.eachRow({ includeEmpty: false }, function(row, rowNumber) {
console.log("Row " + rowNumber + " = " + row.values);
});
});

sudden change in string value during a browse value change

During a Value-Change inside a browse, my string value suddenly changes, specifically the string(9) will change to string(0).
sample:
in my combo-box, i used a list-item-pair with following code:
cb-name:LIST-ITEM-PAIRS = ?.
cb-name:DELIMITER = '?'.
FOR EACH employee WHERE employee.date-resigned = ? NO-LOCK BY employee.employee-no.
cb-name:ADD-LAST(TRIM(STRING(employee.employee-no, '99999999') + " - " + employee.last-name + ", " + employee.first-name + " " + SUBSTRING(employee.middle-name,1,1)) + ".",employee.employee-no).
END.
cb-name:SCREEN-VALUE = cb-name:ENTRY(1).
in the value-changed of browse:
ASSIGN cb-name:SCREEN-VALUE =
STRING(TRIM(STRING(employee.employee-no, '99999999') + " - " + employee.last-name + ", " + employee.first-name + " " + SUBSTRING(employee.middle-name,1,1)) + "." ,
STRING(employee.employee-no, '99999999')).
if the employee no has a string value of 9, progress will change it to 0.. producing an error message that has an invalid value..
ex: from 819001 /*correct*/ to 810001 /*incorrect*/
if there is no string(9), it will display like:818002
if i message the STRING(employee.employee-no, '99999999')), it will display the correct string value
Version doesn't matter in this case, apparently. I just simulated it in 10.2B08 using a temp-table with the named tables. The problem is when you're assigning the screen-value to the combo you're trying to convert the whole string (employee-no + names + separators) into format 99999999.
Since your combo is list-item-pairs
('Whatever I want it to display','the real value',
'and so on display' , 'and so forth value')
your solution is to assign the screen value just to the real value, disregard the label. In other words, as simple as changing your value-changed code to
ASSIGN cb-name:SCREEN-VALUE = STRING(employee.employee-no, '99999999') .
It worked for me. Let me know if you are still having trouble with it.

Resources