Here the working script extension:
// Create script output description
output.markdown( "# Stores with 2+ WO in 30 days" );
// Set Table
const woTable1 = base.getTable( "BR_Details" )
// Set View
const woView1 = woTable1.getView( 'Stores with 2+ WO in 30 days' )
// Get records from view
const woRecords1 = await woView1.selectRecordsAsync().then(result => result.records )
console.log( woRecords1 )
// Set new report name and description
const reportName1 = 'Stores with 2+ WO in 30 days v01'
const reportDescription1 = 'Locations with 2 or more Work Orders in the last 30 days v01'
// create new report including linking of tasks
const reportsTable1 = base.getTable( "Reports" )
const reportRecord1 = await reportsTable1.createRecordAsync(
{
"Name" : reportName1
, "Description" : reportDescription1
, "Linked BR_Details" : woRecords1
} )
if( reportRecord1 ) // Update
{
, {
method : 'post'
, headers : {
'Content-Type' : 'application/json'
, 'Authorization' : 'Bearer 00fb-removed-f0a4ce67a72d'
}
, body : JSON.stringify(
{
recId : reportRecord1
, docId : '669428e9ce0e670ac3eeaf03'
} )
}
)
console.log( res1 )
console.log( await res1.json() )
}
Here is the revised Button click script:
// Create script output description
// output.markdown( "# Stores with 2+ WO in 30 days" );
// Set Table
const woTable1 = base.getTable( "BR_Details" )
// Set View
const woView1 = woTable1.getView( 'Stores with 2+ WO in 30 days' )
// Get records from view
const woRecords1 = woView1.selectRecordsAsync().then(result => result.records )
console.log( woRecords1 )
// Set new report name, description, status and report nbr
const reportName1 = 'Stores with 2+ WO in 30 days v01'
const reportDescription1 = 'Locations with 2 or more Work Orders in the last 30 days v01'
//const reportStatus1 = 'selKruKeOGJP69cpI'
const reportNbr1 = 50
// create new report including linking of tasks
const reportsTable1 = base.getTable( "Reports" )
const reportRecord1 = reportsTable1.createRecordAsync(
{
"Name" : reportName1
, "Description" : reportDescription1
, "Linked BR_Details" : woRecords1
, "Report Nbr" : reportNbr1
} )
// , "Status" : reportStatus1
if( reportRecord1 )
{
, {
method : 'post'
, headers : {
'Content-Type' : 'application/json'
, 'Authorization' : 'Bearer 00fb617c-removed-f0a4ce67a72d'
}
, body : JSON.stringify(
{
recId : reportRecord1
, docId : '669428e9ce0e670ac3eeaf03'
} )
}
)
console.log( res1 ) // Update
// console.log( res1.json() ) // Update
}
// Create script output description
// output.markdown( "# Stores with 3+ WO in 60 days" );
// Set Table
const woTable2 = base.getTable( "BR_Details" )
// Set View
const woView2 = woTable2.getView( 'Stores with 3+ WO in 60 days' )
// Get records from view
const woRecords2 = woView2.selectRecordsAsync().then(result => result.records )
console.log( woRecords2 )
// Set new report name, description, status and report nbr
const reportName2 = 'Stores with 3+ WO in 60 days v01'
const reportDescription2 = 'Locations with 3 or more Work Orders in the last 60 days v01'
// const reportStatus2 = 'In-Progress'
const reportNbr2 = 60
// create new report including linking of tasks
const reportsTable2 = base.getTable( "Reports" )
const reportRecord2 = reportsTable2.createRecordAsync(
{
"Name" : reportName2
, "Description" : reportDescription2
, "Linked BR_Details" : woRecords2
, "Report Nbr" : reportNbr2
} )
// , "Status" : reportStatus2
if( reportRecord2 )
{
, {
method : 'post'
, headers : {
'Content-Type' : 'application/json'
, 'Authorization' : 'Bearer 00fb617c-removed-f0a4ce67a72d'
}
, body : JSON.stringify(
{
recId : reportRecord2
, docId : '6696bbaace0e670ac3eff807'
} )
}
)
console.log( res2 )
// console.log( await res2.json() )
}
The revised script fails with:
Error: Field "fld7oGCicGXHK4kjP" cannot accept the provided value.
at main on line 83
Line 83: const res2 = fetch( 'https://api.docsautomator.co/createDocument'
FYI: Community said it removed HTML ... Thanks for that!!!!!!!!!!!!