multiDatesPicker disable certain dates on a button click - jquery-multidatespicker

How can I add disabled dates to a multiDatesPicker on the click of a button? I was hoping it would be as easy as this, but it this doesn't work. Any help will be very welcome.
Add Disabled Dates
function addDisableDatesOnClick() {
var dateArray = ["07/10/2018", "07/11/2018"];
$('#mdp-demo').multiDatesPicker("addDisabledDates", dateArray);
}

I found the answer. I had to "destroy" and re-create the multiDatesPicker.
function addDisableDatesOnClick() {
$('#mdp-demo').multiDatesPicker('destroy');
var today = new Date();
var y = today.getFullYear();
$('#mdp-demo').multiDatesPicker({
addDates: ['07/5/' + y]
, addDisabledDates: ['07/24/' + y]
, numberOfMonths: [2, 3]
, altField: '#altField'
, defaultDate: '7/1/' + y
});
}

Related

Error in setting line fields in inventory transfer through SS 1.0

I m trying to create an inventory transfer from a suitelet and on setting line fields, system is giving me the error to set at least one item.
ERROR:
"code\":\"USER_ERROR\",\"details\":\"You must enter at least one line item for this transaction"
my code is as follows:
datamap object for lines reflecting as follows:
[{"item":"12482","fromLocation":"17","qtytoadj":"1","amount":null,"remarks":null,"project":"6621","projectTask":null,"matReqId":"8636","itemtype":"InvtPart","islotitem":"F"}]
//creating inventory transfer record
var createInvTrans = nlapiCreateRecord('inventorytransfer');
//Body fields
createInvTrans.setFieldValue('subsidiary', subsidVal);
createInvTrans.setFieldValue('location', 17);
createInvTrans.setFieldValue('transferlocation', 10);
createInvTrans.setFieldValue('custbody21', projectFld);
var toData = dataMap[matRecs];
nlapiLogExecution('debug', 'toData', JSON.stringify(toData))
nlapiLogExecution('debug', 'toData.length', toData.length)
for (var i2 = 0; i2 < toData.length; i2++) {
createInvTrans.selectNewLineItem('inventory');
createInvTrans.setCurrentLineItemValue('inventory', 'item', toData[i2].item);
createInvTrans.setCurrentLineItemValue('inventory', 'adjustqtyby', toData[i2].qtytoadj);
createInvTrans.commitLineItem('inventory');
}
//sumbitting inv Adj
var invTrans = nlapiSubmitRecord(createInvTrans, true, true);
Can anyone help me is there anything that i m doing wrong? because my Data in datamap is right as required but wherever execution reaches to set lines, the error comes.
You're using the wrong mode. You're using the dynamic mode sublist operations with a non-dynamic record.
You could do initialize the transfer as dynamic :
var createInvTrans = nlapiCreateRecord('inventorytransfer', {recordmode: 'dynamic'});
or use the server side api for the sublist:
for (var i2 = 0; i2 < toData.length; i2++) {
createInvTrans.setLineItemValue('inventory', 'item', i2 +1, toData[i2].item);
createInvTrans.setLineItemValue('inventory', 'adjustqtyby', i2+1, toData[i2].qtytoadj);
}

Delete rows after a date has passed automatically for Google Spreadsheets [duplicate]

I'd like to be able to delete an entire row in a Google Spreadsheets if the value entered for say column "C" in that row is 0 or blank. Is there a simple script I could write to accomplish this?
Thanks!
I can suggest a simple solution without using a script !!
Lets say you want to delete rows with empty text in column C.
Sort the data (Data Menu -> Sort sheet by column C, A->Z) in the sheet w.r.t column C, so all your empty text rows will be available together.
Just select those rows all together and right-click -> delete rows.
Then you can re-sort your data according to the column you need.
Done.
function onEdit(e) {
//Logger.log(JSON.stringify(e));
//{"source":{},"range":{"rowStart":1,"rowEnd":1,"columnEnd":1,"columnStart":1},"value":"1","user":{"email":"","nickname":""},"authMode":{}}
try {
var ss = e.source; // Just pull the spreadsheet object from the one already being passed to onEdit
var s = ss.getActiveSheet();
// Conditions are by sheet and a single cell in a certain column
if (s.getName() == 'Sheet1' && // change to your own
e.range.columnStart == 3 && e.range.columnEnd == 3 && // only look at edits happening in col C which is 3
e.range.rowStart == e.range.rowEnd ) { // only look at single row edits which will equal a single cell
checkCellValue(e);
}
} catch (error) { Logger.log(error); }
};
function checkCellValue(e) {
if ( !e.value || e.value == 0) { // Delete if value is zero or empty
e.source.getActiveSheet().deleteRow(e.range.rowStart);
}
}
This only looks at the value from a single cell edit now and not the values in the whole sheet.
I wrote this script to do the same thing for one of my Google spreadsheets. I wanted to be able to run the script after all the data was in the spreadsheet so I have the script adding a menu option to run the script.
/**
* Deletes rows in the active spreadsheet that contain 0 or
* a blank valuein column "C".
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var rowsDeleted = 0;
for (var i = 0; i <= numRows - 1; i++) {
var row = values[i];
if (row[2] == 0 || row[2] == '') {
sheet.deleteRow((parseInt(i)+1) - rowsDeleted);
rowsDeleted++;
}
}
};
/**
* Adds a custom menu to the active spreadsheet, containing a single menu item
* for invoking the readRows() function specified above.
* The onOpen() function, when defined, is automatically invoked whenever the
* spreadsheet is opened.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "Remove rows where column C is 0 or blank",
functionName : "readRows"
}];
sheet.addMenu("Script Center Menu", entries);
};
Test spreadsheet before:
Running script from menu:
After running script:
I was having a few problems with scripts so my workaround was to use the "Filter" tool.
Select all spreadsheet data
Click filter tool icon (looks like wine glass)
Click the newly available filter icon in the first cell of the column you wish to search.
Select "Filter By Condition" > Set the conditions (I was using "Text Contains" > "word")
This will leave the rows that contain the word your searching for and they can be deleted by bulk selecting them while holding the shift key > right click > delete rows.
This is what I managed to make work. You can see that I looped backwards through the sheet so that as a row was deleted the next row wouldn't be skipped. I hope this helps somebody.
function UpdateLog() {
var returnSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('RetLog');
var rowCount = returnSheet.getLastRow();
for (i = rowCount; i > 0; i--) {
var rrCell = 'G' + i;
var cell = returnSheet.getRange(rrCell).getValue();
if (cell > 0 ){
logSheet.
returnSheet.deleteRow(i);
}
}
}
quite simple request. Try this :
function try_It(){
deleteRow(2); //// choose col = 2 for column C
}
function deleteRow(col){ // col is the index of the column to check for 0 or empty
var sh = SpreadsheetApp.getActiveSheet();
var data = sh.getDataRange().getValues();
var targetData = new Array();
for(n=0;n<data.length;++n){
if(data[n][col]!='' && data[n][col]!=0){ targetData.push(data[n])};
}
Logger.log(targetData);
sh.getDataRange().clear();
sh.getRange(1,1,targetData.length,targetData[0].length).setValues(targetData);
}
EDIT : re-reading the question I'm not sure if the question is asking for a 'live' on Edit function or a function (like this above) to apply after data has been entered... It's not very clear to me... so feel free to be more accurate if necessary ;)
There is a simpler way:
Use filtering to only show the rows which you want to delete. For example, my column based on which I want to delete rows had categories on them, A, B, C. Through the filtering interface I selected only A and B, which I wanted to delete.
Select all rows and delete them. Doing this, in my example, effectively selected all A and B rows and deleted them; now my spreadsheet does not show any rows.
Turn off the filter. This unhides my C rows. Done!
There is a short way to solve that instead of a script.
Select entire data > Go to menu > click Data tab > select create filter > click on filter next to column header > pop-up will appear then check values you want to delete > click okay and copy the filtered data to a different sheet > FINISH
reading your question carefully, I came up with this solution:
function onOpen() {
// get active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
// create menu
var menu = [{name: "Evaluate Column C", functionName: "deleteRow"}];
// add to menu
ss.addMenu("Check", menu);
}
function deleteRow() {
// get active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
// get active/selected row
var activeRow = ss.getActiveRange().getRowIndex();
// get content column C
var columnC = ss.getRange("C"+activeRow).getValue();
// evaluate whether content is blank or 0 (null)
if (columnC == '' || columnC == 0) {
ss.deleteRow(parseInt(activeRow));
}
}
This script will create a menu upon file load and will enable you to delete a row, based on those criteria set in column C, or not.
This simple code did the job for me!
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet(); // get active spreadsheet
var activeRow = ss.getActiveRange().getRowIndex(); // get active/selected row
var start=1;
var end=650;
var match='';
var match2=0; //Edit this according to your choice.
for (var i = start; i <= end; i++) {
var columnC = ss.getRange("C"+i).getValue();
if (columnC ==match || columnC ==match2){ ss.deleteRow(i); }
}
}
The below code was able to delete rows containing a date more than 50 days before today in a particular column G , move these row values to back up sheet and delete the rows from source sheet.
The code is better as it deletes the rows at one go rather than deleting one by one. Runs much faster.
It does not copy back values like some solutions suggested (by pushing into an array and copying back to sheet). If I follow that logic, I am losing formulas contained in these cells.
I run the function everyday in the night (scheduled) when no one is using the sheet.
function delete_old(){
//delete > 50 day old records and copy to backup
//run daily from owner login
var ss = SpreadsheetApp.getActiveSpreadsheet();
var bill = ss.getSheetByName("Allotted");
var backss = SpreadsheetApp.openById("..."); //backup spreadsheet
var bill2 = backss.getSheetByName("Allotted");
var today=new Date();
//process allotted sheet (bills)
bill.getRange(1, 1, bill.getMaxRows(), bill.getMaxColumns()).activate();
ss.getActiveRange().offset(1, 0, ss.getActiveRange().getNumRows() - 1).sort({column: 7, ascending: true});
var data = bill.getDataRange().getValues();
var delData = new Array();
for(n=data.length-1; n>1; n--){
if(data[n][6] !=="" && data[n][6] < today.getTime()-(50*24*3600*1000) ){ //change the condition as per your situation
delData.push(data[n]);
}//if
}//for
//get first and last row no to be deleted
for(n=1;n<data.length; n++){
if(data[n][6] !=="" && data[n][6] < today.getTime()-(50*24*3600*1000) ){
var strow=n+1 ; //first row
break
}//if
}//for
for(n=data.length-1; n>1; n--){
if(data[n][6] !=="" && data[n][6] < today.getTime()-(50*24*3600*1000) ){
var ltrow=n+1 ; //last row
break
}//if
}//for
var bill2lr=bill2.getLastRow();
bill2.getRange((bill2lr+1),1,delData.length,delData[0].length).setValues(delData);
bill.deleteRows(strow, 1+ltrow-strow);
bill.getRange(1, 1, bill.getMaxRows(), bill.getMaxColumns()).activate();
ss.getActiveRange().offset(1, 0, ss.getActiveRange().getNumRows() - 1).sort({column: 6, ascending: true}); //get back ordinal sorting order as per column F
}//function

Javascript unwanted cell removal from a table

I want to copy paste from excel to webpage. This issue is resolved using Copy/Paste from Excel to a web page
However now I want these fields to be editable and submit it in a form. So I changed the code to :
function generateTable() {
var data = $('textarea[name=excel_data]').val();
console.log(data);
var rows = data.split("\n");
var table = $('<table />');
var counterRow = 0;
var counterCol = 0;
for(var y in rows) {
var cells = rows[y].split("\t");
var row = $('<tr />');
for(var x in cells) {
row.append('<td border-collapse:collapse>' + '<textarea style="overflow:auto" name=' + counterRow + counterCol + '>' +cells[x]+'</textarea>'+'</td>');
counterCol++;
}
counterRow++;
table.append(row);
}
// Insert into DOM
$('#excel_table').html(table);
}
The problem is : there is an additional row containing 1 cell displayed towards the end of the table.
___________
|___|___|___|
|___|___|___|
|___|
I had to use this if clause inside the for :
if(rows[y]){

Adding new element to Array - Swift 3

I have a Tableviewcontroller BeamsNameVC with 2 variables: Name and number.
If for example, the number is 7, and if I click on any row in this View controller, it will segue to another TableViewcontroller SpansListVC and than it will show 7 rows: S1, S2, S3, S4, S5, S6 & S7.
I want to save these Data, so I created 2 swift files:
class StructureElement: NSObject, NSCoding {
var name = ""
var nbrSpans = ""
var spans = [LoadDetailsForEachSpan]()
and
class LoadDetailsForEachSpan: NSObject, NSCoding {
var i_SpanName = ""
var i_Spanlength = ""
var i_ConcentratedLoadForEachSpans = [ConcentratedLoadForEachSpan]()
I created a protocol with the following:
let spanNbr = Int(structureElement[newRowIndex].nbrSpans)
let newElementDetailSpan = LoadDetailsForEachSpan()
for i in 0...spanNbr! {
newElementDetailSpan.i_SpanName = "S" + " \(i)"
structureElement[newRowIndex].spans.append(newElementDetailSpan)
}
If i run the application, it will segue to * SpansListVC* but all values are the last i.
Example:
if name is Test 7 and number of span is 7, I will be having inside *[Spans] * 7 values with the same name:
spans[0] = S 7
spans[1] = S 7
....
Any mistake with above code?
Welcome to the hell that mutable data objects can be ;). You are creating a single LoadDetailsForEachSpan instance and add that same instance a number of times to the array, while setting the i_SpanName property of that same instance every time the loop is iterated. You probably want to pull the instance creation into the loop:
for i in 0...spanNbr! {
let newElementDetailSpan = LoadDetailsForEachSpan()
newElementDetailSpan.i_SpanName = "S" + " \(i)"
structureElement[newRowIndex].spans.append(newElementDetailSpan)
}
Thanks #thm for your reply.
however, i find another solution as follow and it works:
var spanDetailAndLoadItem: [SpanDetailsAndLoads] = []
for var i in 1...nbr! {
let item = SpanDetailsAndLoads(name: "S\(i) - S\(i + 1)")
spanDetailAndLoadItem.append(item)
}
self.spans = spanDetailAndLoadItem

Disable/enable an input field

Using this sample code, I am trying to enable/disable the field "arrdatfrom". However, once this text field has been DISABLED, i cannot get it to be re-ENABLED. The function below gets executed when the user clicks a "Refresh" button. I have built this little demo just to prove that I have tried many ways to do this. Any ideas?
function showBooking() {
var d = new Date()
formvals.arrdatefrom = document.getElementById("arrdatfrom").value
formvals.arrdatethru = document.getElementById("arrdatthru").value
formvals.depdatefrom = document.getElementById("depdatfrom").value
formvals.depdatethru = document.getElementById("depdatthru").value
formvals.bookname = document.getElementById("bookname").value
formvals.peakroomfrom = document.getElementById("peakroomfrom").value
formvals.peakroomthru = document.getElementById("peakroomthru").value
formvals.peakattendfrom = document.getElementById("peakattendfrom").value
formvals.peakattendthru = document.getElementById("peakattendthru").value
alert (' ngs.hta ready to enable')
document.getElementById("arrdatfrom").enabled = 'true'
alert ('ngs.hta in showBooking!! disable. ')
document.getElementById("arrdatfrom").disabled = 'true'
...
There is no property .enabled. To re-enable a disabled element, set .disabled = false.

Resources