Whatever message this page gives is out now! Go check it out!

TransactGetItems

Last update:
May 18, 2026

Description

This function retrieves one oe more items from one or more tables in a single account and region.
For more information, see TransactGetItems.

Category

History

ColdFusion (2021 release): Added this function.

Syntax

serviceHandle.transactGetItems(requestParameters)

Parameters

See request parameters of TransactGetItems.

Example

<cfscript> 
    cred = { 
        "credentialAlias" : "myalias", 
        "vendorName" : "AWS", 
        "region" : "us-east-2", 
        "secretAccessKey" : "xxxxx", 
        "accessKeyId" : "xxxx" 
  } 
    config = { 
        "serviceName" = "DYNAMODB" 
      } 
    dynamo = cloudService(cred, config) 
 
    // create table Customer 
    createTable_customers = { 
        "TableName": "CustomerUpd", 
        "KeySchema": [ 
            { 
                "AttributeName": "CustomerId", 
                "KeyType": "HASH" 
            } 
        ], 
        "AttributeDefinitions": [ 
            { 
                "AttributeName": "CustomerId", 
                "AttributeType": "S" 
            } 
        ], 
        "ProvisionedThroughput": { 
            "ReadCapacityUnits": 10, 
            "WriteCapacityUnits": 10 
        } 
    } 
 
    // create table product 
    createTable_product = { 
        "TableName": "Product", 
        "KeySchema": [ 
            { 
                "AttributeName": "ProductId", 
                "KeyType": "HASH" 
            } 
        ], 
        "AttributeDefinitions": [ 
            { 
                "AttributeName": "ProductId", 
                "AttributeType": "N" 
            } 
        ], 
        "ProvisionedThroughput": { 
            "ReadCapacityUnits": 10, 
            "WriteCapacityUnits": 10 
        } 
    } 
 
    // create table Orders 
    createTable_orders = { 
        "TableName": "Orders", 
        "KeySchema": [ 
            { 
                "AttributeName": "OrderId", 
                "KeyType": "HASH" 
            } 
        ], 
        "AttributeDefinitions": [ 
            { 
                "AttributeName": "OrderId", 
                "AttributeType": "N" 
            } 
        ], 
        "ProvisionedThroughput": { 
            "ReadCapacityUnits": 10, 
            "WriteCapacityUnits": 10 
        } 
    } 
 
    // create all three tables 
    dynamo.createTable(createTable_customers) 
    dynamo.createTable(createTable_product) 
    dynamo.createTable(createTable_orders) 
 
    // define structs for items to be inserted into the tables 
    strct_putItem1 = { 
        "TableName": "CustomerUpd", 
        "Item":{ 
            "CustomerId": { 
                "S": "09e8e9c8-ec48" 
            } 
        } 
    } 
 
    strct_putItem2 = { 
        "TableName": "Product", 
        "Item":{ 
            "ProductId": { 
                "N": 1234 
            }, 
            "producttatus": { 
                "S": "IN_STOCK" 
            } 
        } 
    } 
 
    // put items in the tables 
    dynamo.putItem(strct_putItem1, {"hasType": true}) 
    dynamo.putItem(strct_putItem2, {"hasType": true}) 
 
    //STORE DATA IN TABLE AFTER TRANSACTION 
    CUSTOMER_TABLE_NAME = "CustomerUpd"; 
    CUSTOMER_PARTITION_KEY = "CustomerId"; 
    customerId = "09e8e9c8-ec48"; 
    conditionCheck = { 
        "TableName": CUSTOMER_TABLE_NAME, 
        "Key": { 
            "#CUSTOMER_PARTITION_KEY#": { 
                "S": customerId 
            } 
        }, 
        "ConditionExpression": "attribute_exists(#CUSTOMER_PARTITION_KEY#)", 
        "ReturnValuesOnConditionCheckFailure": "ALL_OLD" 
    } 
 
    PRODUCT_TABLE_NAME = "Product"; 
    PRODUCT_PARTITION_KEY = "ProductId"; 
    PRODUCT_PARTITION_KEY_VALUE = 1234; 
    updateproducttatus = { 
        "TableName": PRODUCT_TABLE_NAME, 
        "Key": { 
            "#PRODUCT_PARTITION_KEY#": { 
                "N": PRODUCT_PARTITION_KEY_VALUE 
            } 
        }, 
        "UpdateExpression": "SET producttatus = :new_status", 
        "ExpressionAttributeValues": { 
            ":new_status": { 
                "S": "SOLD" 
            }, 
            ":expected_status": { 
                "S": "IN_STOCK" 
            } 
        }, 
        "ConditionExpression": "producttatus = :expected_status", 
        "ReturnValuesOnConditionCheckFailure": "ALL_OLD" 
    } 
 
    ORDER_PARTITION_KEY = "OrderId"; 
    ORDER_TABLE_NAME = "Orders"; 
    ORDER_PARTITION_KEY_VALUE = 740; 
    createOrder = { 
        "TableName": ORDER_TABLE_NAME, 
        "Item": { 
            "#ORDER_PARTITION_KEY#": { 
                "N": ORDER_PARTITION_KEY_VALUE 
            }, 
            "#PRODUCT_PARTITION_KEY#": { 
                "N": PRODUCT_PARTITION_KEY_VALUE 
            }, 
            "#CUSTOMER_PARTITION_KEY#": { 
                "S": customerId 
            }, 
            "OrderStatus": { 
                "S": "CONFIRMED" 
            }, 
            "OrderTotal": { 
                "N": 100 
            } 
        }, 
        "ReturnValuesOnConditionCheckFailure": "ALL_OLD", 
        "ConditionExpression": "attribute_not_exists(#ORDER_PARTITION_KEY#)" 
    } 
 
    transactWriteItems = { 
        "TransactItems": [{  
            "ConditionCheck": conditionCheck 
        }, { 
            "Update": updateproducttatus 
        }, { 
            "Put": createOrder 
        }], 
        "ReturnConsumedCapacity": "TOTAL" 
    } 
 
    //READ DATA AFTER TRANSACTION COMPLETES 
    readproductold = { 
        "TableName": PRODUCT_TABLE_NAME, 
        "Key": { 
            "#PRODUCT_PARTITION_KEY#": { 
                "N": PRODUCT_PARTITION_KEY_VALUE 
            } 
        } 
    } 
 
    readCreatedOrder = { 
        "TableName": ORDER_TABLE_NAME, 
        "Key": { 
            "#ORDER_PARTITION_KEY#": { 
                "N": ORDER_PARTITION_KEY_VALUE 
            } 
        } 
    } 
 
    transactGetItems = { 
        "TransactItems": [ 
            { 
                "Get": readproductold 
            }, 
            { 
                "Get": readCreatedOrder 
            } 
        ], 
        "ReturnConsumedCapacity": "TOTAL" 
    } 
 
    // Transact write items 
    try{ 
        resultWrite = dynamo.transactWriteItems(transactWriteItems, {"hasType":true}) 
        writeOutput("TransactionWriteItems Successful<br />") 
        writeDump(resultWrite) 
    } 
    catch (any e){ 
        writeDump(e) 
    } 
 
    // Transact get items 
    try{ 
        resultGet=dynamo.transactGetItems(transactGetItems,{"hasType":true}) 
        writeDump(resultGet) 
    } 
    catch (any e){ 
        writeDump(e) 
    } 
</cfscript>

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page