Help

Script to add dates to a table

Topic Labels: Scripting extentions
838 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Andrew_Davies
7 - App Architect
7 - App Architect

Hi

I am a bit stuck with this one, and not well versed in scripting / coding. Though I think it should be fairly simple to do?

I have two tables :

A - A range of dates spanning a month or so. Dates are always consecutive, so 12th May, 13th May, 14th May etc
B - A list of people with a field for start date, and a field for end date (this is manipulated using a Timeline view and works well),

I’m trying to write a script that updates a linked record from Table B to Table A for each start date, end date and every date in between. This is used to work out when someone needs a hotel room booking.

For example

Table A - 1st May to 30th May - 30 records
Table B
Joe Bloggs - Start 10th May, End 14th May
Bert Reynolds - Start 14th May, end 20th May

I’d have a field in Table A called “Accommodation” which links to Joe Bloggs in Table B on the records for 10th, 11th, 12th and 13th May

Also in Table A, the accommodation field would have a link to Bert in Table B for records from 14th May to 20th May

Table A would then be a really useful Master accommodation list for the project (amongst other things)

May seem odd, but I’d have another table with a lot of detail for things that happen on each day.

Hope that makes sense? Any ideas well received

Regards,
Andrew

1 Reply 1
Andrew_Davies
7 - App Architect
7 - App Architect

I’ve tried the below, but am getting a “TypeError: inputConfig.record_id.getCellValue is not a function or its return value is not iterable” error. Note I have put in a dummy value for ‘newForeignRecordIdToLink’ just while testing.

let table = base.getTable(“Logistics - dates”);
let inputConfig = input.config();
console.log(The value of record_id is ${inputConfig.record_id});
console.log(The value of start_date is ${inputConfig.start_date});
console.log(The value of end_date is ${inputConfig.end_date});

let start = new Date(inputConfig.start_date);
let end = new Date(inputConfig.end_date);

var loop = new Date(start);
while(loop <= end){

var newDate = loop.setDate(loop.getDate() + 1);
loop = new Date(newDate);
console.log(“Looping!”,loop);

newForeignRecordIdToLink = 'recd7OtUazprGfJ1L'; //Just for testing - needs to be updated
table.updateRecordAsync(inputConfig.record_id, {
'Room nights': [
    ...inputConfig.record_id.getCellValue('Room nights'),
    { id: newForeignRecordIdToLink }
]

})

}