Populate image based on pick list

Viewing 0 reply threads
  • Author
    Posts
  • July 24, 2019 at 10:46 PM #36042

    Sam Moffatt
    Participant

    In Linking Images in a Database an ask was made to pick images and whilst that’d be cool to see somehow with form links, I decided to implement this as a quick field script as an example though a Link from Form field with the ability to embed a custom layout I think would be a cool way to solve the problem..

    This script borrows some publicly available images to solve the problem and uses a picklist to limit choices. I noticed I needed to hit refresh because the field script wasn’t being triggered. It will also not do anything if an image is already there, you have to manually delete the image to change it. Very simple sample form attached as well.

    var disc_type = record.getFieldValue('fld-d829341555114d4fb0a1f6d05a80930a');
    var disc_type_logo = record.getFieldValue('fld-9cd36df80c1141d4a87f59496222ebb0');
    console.log(disc_type);
    console.log(JSON.stringify(disc_type_logo));
    
    if (!disc_type_logo.length)
    {
    	var url = '';
    	switch (disc_type)
    	{
    		case 'CD':
    			url = 'http://pluspng.com/img-png/file-cd-logo-png-1024.png';			break;
    		case 'DVD':
    			url = 'http://pluspng.com/img-png/dvd-movie-png-dvd-logo-600.png';			break;
    		case 'Bluray':
    			url = 'http://pluspng.com/img-png/ama-flat-track-logo-vector-png-blu-ray-disc-logo-400.png';
    			break;
    		case 'LP':
    			url = 'http://pluspng.com/img-png/turntable-hd-png-turntables-png-cliparts-2640178-1000.png';
    			break;
    	}
    	if (url.length)
    	{
    		record.addPhotoFromUrlToField(url, 'fld-9cd36df80c1141d4a87f59496222ebb0');
    	}
    }
    else
    {
    	console.log('Skipping setting logo');
    }
    
    console.log('All done');
    
    Attachments:
    You must be logged in to view attached files.
Viewing 0 reply threads

You must be logged in to reply to this topic.