Creatio development guide
PDF
This documentation is valid for Creatio version 7.16.0. We recommend using the newest version of Creatio documentation.

Modifying data

Glossary Item Box

Examples of using the Update class to build queries for updating database records

You can download the package with the configuration web service implementing the cases described below using the following link.

In most cases, a request for modification should contain the “Where” condition, which specifies which records exactly should be modified. Otherwise, all records will be modified.

Example 1

Receive the SQL-query text
 
 
public string GetSqlTextExample(string oldName, string newName)
{
    var result = "";
    var update = new Update(UserConnection, "Contact")
        .Set("Name", Column.Parameter(newName))
        .Where("Name").IsEqual(Column.Parameter(oldName));
    result = update.GetSqlText();
    return result;
}

Example 2

Change the contact name to another one
 
 
 public string ChangeContactName(string oldName, string newName)
{
    var update = new Update(UserConnection, "Contact")
        .Set("Name", Column.Parameter(newName))
        .Where ("Name").IsEqual(Column.Parameter(oldName));
    var cnt = update.Execute();
    return $"Contacts {oldName} changed to {newName}. {cnt} rows affected.";
}

Example 3

Change the user that has modified all existing contact records, to the specified user.
 
 
public string ChangeAllContactModifiedBy(string Name)
{
    var update = new Update(UserConnection, "Contact")
        .Set("ModifiedById", 
            new Select(UserConnection).Top(1)
                .Column("Id")
                .From("Contact")
                .Where("Name").IsEqual(Column.Parameter(Name)));
    var cnt = update.Execute();
    return $"All contacts are changed by {Name} now. {cnt} rows affected.";
}

In this example, the Where condition refers to the Select request. The Update request does not contain the Where condition, since indiscriminate modification is the goal.

See also:

© Creatio 2002-2020.

Did you find this information useful?

How can we improve it?