Is g_form.save() async?

Jaeik Lee
Mega Sage

I made UI Page that called by UI Action. Inside of UI Page, some values changed by g_form.setValue. and below the script, It called Scripted Include that using changed value. there was code.

 

...

g_form.setValue('u_report_state', 1);

g_form.save(); 

 

method1(); // that method call Script Include.

method2();

 

Unfortunately, Script Include cannot get Value as "1" that changed by g_form.setValue(). So I think g_form.save() was async. But not sure.

 

Thnak you for help If tell me reason of that.

1 ACCEPTED SOLUTION

@Jaeik Lee 

Yes, Business Rules are server-side scripts that run when records are inserted, updated, or deleted in the database. The timing of when these Business Rules run (before or after the database operation) is controlled by the "When to run" setting (Before, After, or Async).

Given your scenario, it's important to understand the timing:

  1. Before Business Rule: Runs before the record is inserted or updated in the database.
  2. After Business Rule: Runs after the record has been inserted or updated in the database.
  3. Async Business Rule: Runs asynchronously after the record operation is complete, but not necessarily immediately.

When you use g_form.save() in a client script, it triggers the database update process. Here’s how it works with Business Rules:

  • Before Business Rule: This runs before the record is actually saved to the database. So, if you need to manipulate data before it gets saved, this is where you do it.
  • After Business Rule: This runs after the record has been saved to the database. If you have operations that need to happen only after the data is committed, use this.
  • Async Business Rule: This runs independently and is useful for operations that do not need to block the transaction, such as logging or notifying external systems.

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

View solution in original post

3 REPLIES 3

Maddysunil
Kilo Sage

@Jaeik Lee 

When you use g_form.setValue() and g_form.save(), the changes are made on the client side, but the save operation is indeed asynchronous. This means that the save operation might not complete before the subsequent methods (method1() and method2()) are executed, leading to a scenario where the Script Include called in method1() does not have the updated value yet.

To handle this, you need to ensure that method1() is called only after g_form.save() has successfully completed. You can achieve this by using a callback function with g_form.save()

 

function onSaveComplete() {
    method1(); // Call your method that includes the Script Include
    method2(); // Call your other method
}

// Set the value
g_form.setValue('u_report_state', 1);

// Save the form and provide a callback function
g_form.save().then(onSaveComplete);

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Thank you for answer. there was another issue about that. When i use Business Rule that triggered when value changes. Business Rule always run AFTER g_form.save() finished?

@Jaeik Lee 

Yes, Business Rules are server-side scripts that run when records are inserted, updated, or deleted in the database. The timing of when these Business Rules run (before or after the database operation) is controlled by the "When to run" setting (Before, After, or Async).

Given your scenario, it's important to understand the timing:

  1. Before Business Rule: Runs before the record is inserted or updated in the database.
  2. After Business Rule: Runs after the record has been inserted or updated in the database.
  3. Async Business Rule: Runs asynchronously after the record operation is complete, but not necessarily immediately.

When you use g_form.save() in a client script, it triggers the database update process. Here’s how it works with Business Rules:

  • Before Business Rule: This runs before the record is actually saved to the database. So, if you need to manipulate data before it gets saved, this is where you do it.
  • After Business Rule: This runs after the record has been saved to the database. If you have operations that need to happen only after the data is committed, use this.
  • Async Business Rule: This runs independently and is useful for operations that do not need to block the transaction, such as logging or notifying external systems.

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks