Modify data in the database
Level: advanced
note
The examples in this article are also implemented in the web service. The package that contains the web service implementation is attached in the Resources block.
In most cases, a modification query must contain the Where
condition, which specifies the exact records to modify. If you do not specify the Where
condition, Creatio will modify all records.
Example 1
Example
Change the contact name.
ChangeContactName() method
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 2
Example
Change the user that modified the contact record to the specified user for all existing contacts.
ChangeAllContactModifiedBy() method
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.";
}
The Where
condition refers to the Select
query. The Update
query does not contain the Where
condition since the goal is to modify all records.