Copy Single-Select Field

Use Case
working on my deep copy function. Just need to copy the current value of a single-select field from a source task to a target task in a js automationm script.

Vars
Database - source/target space/database: ‘Test/Task’
fieldname - name of the single-select field: ‘Task Type’
fieldValueSource - the Task Type object in fieldName:
{ Id: ‘e3b3f211-0e44-11ee-830c-6d1d3c8b35f0’, Name: ‘TASK’ }
entityTarget - the target Task entity

Question
Could someone pls provide the correct syntax to update entityTarget with the Task Type from fieldValueSource?

Note
I have spent hours trying to get this to work. In Scripts and Automation there is a list of functions. I think it would be very useful to the community if this could be expanded to include syntax and examples.

Thx

Generally, for a select field

await fibery.updateEntity(typeName, entityId { fieldName : fieldValue });

typeName = full name of database, e.g. “Space/Database”
entityId = UUID of entity to be updated, e.g. “3bba5590-fee4-11ee-b169-d12157290ac4”
fieldName = name of field, e.g. “Task Type”
fieldValue = select option to be chosen, e.g. “Task”

In general, the tooltips will show you the syntax for a function as you start typing, and some explanation.

firefox_5OA4FTV5If

@Chr1sG - many thx for the quick reply (over the weekend, no less!)

I was able to get it working with hardcoded literals, so now I just need to figure out why my vars are causing an issue, but that’s simple enough.

I’m just about done with my script - your help is always greatly appreciated!

async function updateFieldSelectSingle(Database, fieldName, fieldValueSource, entityTarget) {


    if (fieldValueSource) {
        let fieldValueTarget = fieldValueSource;

        await fibery.updateEntity(
            Database, entityTarget.id, {
                'Task Type - SW': 'TASK'
            }
        )
    }
}