Action

Clean Conference Photo List

Posted by sylumer, Last update 13 days ago - Unlisted

Clear down all but the last photo

Steps

  • script

    // Initialise
    const BASEID = "appYfCcGSmGO1BzLS"
    const TABLE = "Image"
    
    // Clear down all images bu the last one
    let at = new Airtable()
    let recImage = at.listRecords(BASEID, TABLE);
    
    // No Processing required
    let intCount = recImage.records.length;
    if(intCount == 0) app.displayWarningMessage("No need to clean up - no images found");
    if(intCount == 1) app.displayWarningMessage("No need to clean up - one image found");
    
    // Processing required = last image will be the last one in the array
    if(intCount > 1)
    {
    	// Delete all but the most recent entry in Airtable
    	recImage.records.slice(0,-1).map(recRow => 
    	{
    		let atSettings = {};
    		atSettings.url = `https://api.airtable.com/v0/${BASEID}/${TABLE}/${recRow.id}`
    		atSettings.method = "DELETE";
    		let respAT = at.request(atSettings);
    		if (respAT) console.log(`${recImage.records[0].id} deleted from ${BASEID}/${TABLE}`);
    		else context.fail(`Error deleting ${recImage.records[0].id}from ${BASEID}/${TABLE}`);
    	});
    	app.displayInfoMessage(`Removed ${intCount - 1} records of ${intCount}`);
    }

Options

  • After Success Default
    Notification Error
    Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.