Hello.
I'm trying to save a pdf file that i get from a service web, the file comes in a base64 string so i use a script to convert it to a pdf and save it in Creatio, I have this code that works fine for the Accounts section but when i want to save the file in a Custom section, the process send me an error sometimes because it doesnt find the Id other because it says that the duplicate key value violates unique constraint.
This is the code that works in the Accounts Section.
var base64FileString = Get<string>("Base64File");
var accountId = Get<Guid>("AccountId");
var attachFileType = new Guid("529bc2f8-0ee0-df11-971b-001d60e938c6");
var fileName = Get<string>("NameFile"); // set proper file type
var entity = UserConnection.EntitySchemaManager.GetInstanceByName("AccountFile");
var fileEntity = entity.CreateEntity(UserConnection);
fileEntity.SetDefColumnValues();
fileEntity.SetColumnValue("AccountId", accountId);
fileEntity.SetColumnValue("TypeId", attachFileType);
fileEntity.SetColumnValue("Name",fileName);
fileEntity.SetBytesValue("Data", Convert.FromBase64String(base64FileString));
fileEntity.Save();
return true;
And this is the code that I want to use in the custom section
var base64FileString = Get<string>("Base64File");
var resguardoId = Get<Guid>("ResguardoId");
var attachFileType = new Guid("529bc2f8-0ee0-df11-971b-001d60e938c6");
var fileName = Get<string>("NameFile"); // set proper file type
var entity = UserConnection.EntitySchemaManager.GetInstanceByName("SysFile");
var fileEntity = entity.CreateEntity(UserConnection);
fileEntity.SetDefColumnValues();
fileEntity.SetColumnValue("ResguardoId", resguardoId);
fileEntity.SetColumnValue("TypeId", attachFileType);
fileEntity.SetColumnValue("Name",fileName);
fileEntity.SetBytesValue("Data", Convert.FromBase64String(base64FileString));
fileEntity.Save();
return true;