Help Center/ Huawei Cloud Astro Zero/ FAQs/ Application Backend Development/ Can I Roll Back a Script Diagram Element That Involves Data Operations in Flows If Other Diagram Elements Fail to Be Operated?
Updated on 2025-08-14 GMT+08:00

Can I Roll Back a Script Diagram Element That Involves Data Operations in Flows If Other Diagram Elements Fail to Be Operated?

If a script involves operations such as adding, deleting, and modifying data, a rollback is performed by default for the diagram element after other script diagram elements failed. If an independent transaction is written in the script, the rollback is not performed.

Figure 1 Script diagram element

The following shows the format of an independent transaction. If the script includes the bolded content, the independent transaction is enabled. Even if the flow referencing this transaction fails, the transaction operation will not be rolled back.

import * as db from 'db';

@userObject(['student__cst'])
class Demo{
   test():void{
        let student = db.object('student__cst');
		//Perform some database operations.
        let op =function(): viod{
		    //Perform other database operations.
        };
	//The database operations in op are independent transactions and do not affect the transaction operations outside op.
        db.transaction(op)
		}
	}

Use db.transaction to perform a series of operations in a transaction, either all successful or all failed. The success or failure of db.transaction is independent of external operations, and vice versa.