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; 

 

 

Like 0

Like

4 comments

The SysFile entity doesn't, and won't, have a "ResguardoId" column. It has generic columns so it can work with any entity. Instead of setting ResguardoId, set the following: 

  • RecordId - the Id of the record (the value for ResguardoId)
  • RecordSchemaName - the name of the entity for the RecordId (whatever the entity name is for ResguardoId)

Ryan

Ryan Farley,

 

Thank you 

 

I'm made the change, the process starts without any error but the file is not save it in the record.

 

var base64FileString = Get&lt;string&gt;("Base64File");
var recordId = Get&lt;Guid&gt;("RecordId");
 
var attachFileType = new Guid("529bc2f8-0ee0-df11-971b-001d60e938c6");
var fileName ="New.pdf"; // set proper file type
 
var entity = UserConnection.EntitySchemaManager.GetInstanceByName("SysFile");
var fileEntity =  entity.CreateEntity(UserConnection);
fileEntity.SetDefColumnValues();
fileEntity.SetColumnValue("RecordId", recordId);
fileEntity.SetColumnValue("TypeId", attachFileType);
fileEntity.SetColumnValue("Name",fileName);
fileEntity.SetBytesValue("Data", Convert.FromBase64String(base64FileString));
fileEntity.Save();
return true; 

Laura Jurado,

You also need to populate the RecordSchemaName property - refer back to my previous comment.

Ryan

Show all comments

Hello Community,

 

I have a few questions about GUIDs:

 

Q1. Is it possible to create custom GUID series for different standard objects? 
 

For example, can I generate custom GUIDs where every customer record starts with `0000001`, contacts with `0000002`, and orders with `0000003`?
  - Example:
    1. Customers: `0000001-3cfa-4daf-a93c-632cb2420805`
    2. Contacts: `0000002-4akk-5fhg-d19c-42080asb2420`
    3. Orders: `0000003-4akk-5fhg-d19c-42080asb2420`

 

Q2. Can I identify the Object Name just by looking at the GUID of a record?

 

Regards, 

Ajay

 

Like 0

Like

1 comments

Greetings!
 

Unfortunately, we do not recommend creating custom GUIDs, as this may lead to issues with the application.


You can copy the GUID, paste it into the search field in 
Configuration, and select "filter by contains GUID" for further filtering.


Regards,
Orkhan 

Show all comments

I am developing a business process that takes data from an API and inserts it into an object.
I have some parameters created in it and I need to make some improvements to be able to insert them.
The parameters in question are the following, UserName = Text and UserApi = Lookup (Based on Contact)
I am trying to relate the username with the userapi lookup so that later this userapi is inserted into the contact lookup in the destination object:
// Obtener la fecha de la API, puede ser un string o "false"
string fechaApi = Get("FechaApertura");
string XStudioUsuarios = Get("XStudioUsuarios");
string ExpectedRevenue = Get("ExpectedRevenue");
string UserName = Get("UserName");
Guid UserApi = Get("UserApi");

// Declarar la variable para almacenar la nueva fecha
DateTime fechaNueva;
int XStudioUsuariosInt;
int ExpectedRevenueInt;

if (!string.IsNullOrEmpty(UserName) && UserName != "false") {
   Set("UserApi.Name", UserName);
}

if (fechaApi != "false") {
   // Intentar parsear el string de fecha a DateTime
   if (DateTime.TryParse(fechaApi, out fechaNueva)) {
       // Establecer la nueva fecha si el parseo fue exitoso
       Set("FechaAperturaNueva", fechaNueva);
   }
}

if (XStudioUsuarios != "false") {
   // Intentar parsear el string a int
   if (int.TryParse(XStudioUsuarios, out XStudioUsuariosInt)) {
       // Establecer el nuevo valor si el parseo fue exitoso
       Set("XStudioUsuariosInt", XStudioUsuariosInt);
   }
}

if (ExpectedRevenue != "false") {
   // Intentar parsear el string a int
   if (int.TryParse(ExpectedRevenue, out ExpectedRevenueInt)) {
       // Establecer el nuevo valor si el parseo fue exitoso
       Set("ExpectedRevenueInt", ExpectedRevenueInt);
   }
}

return true;

Like 0

Like

3 comments

One of the options is to use the ORM. The idea here is to first check if the received text value is already present in the lookup or not. To do that perform a simple select from the entity of the lookup and check if there are values there that are the same as the received text value. Examples of retrieving data can be found here. If the value is present in the lookup - set the Id of that lookup record for your main record lookup column (as described in the examples here).

 

If the value doesn't exist in the lookup - create it and then set the Id of the created lookup record as the value for the lookup column in your main record.

Oleg Drobina,

Thanks Oleg, what you describe is exactly what I need to do, but I still don't know how I can do it.

Oleg i do this Code with the information than you gave me:


string fechaApi = Get<string>("FechaApertura");
string XStudioUsuarios = Get<string>("XStudioUsuarios");
string ExpectedRevenue = Get<string>("ExpectedRevenue");
string UserName = Get<string>("UserName");
Guid UserApi = Get<Guid>("UserApi");


DateTime fechaNueva;
int XStudioUsuariosInt;
int ExpectedRevenueInt;

if (!string.IsNullOrEmpty(UserName) && UserName != "false") {
    
   var esq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "Contact");
    var idColumn = esq.AddColumn("Id");
    esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "Name", UserName));
    var entityCollection = esq.GetEntityCollection(UserConnection);
    
    // Verificar si se encontraron resultados
    if (entityCollection.Count > 0) {
        var entity = entityCollection[0];

        var userApiLookup = new {
           Value = entity.GetTypedColumnValue<Guid>(Id.Name),
           DisplayValue = entity.GetTypedColumnValue<string>(Name.Name)
       };
    
        // Establecer el objeto Lookup en UserApi
        Set<Guid>("UserApi", userApiLookup);
    } 
}

if (fechaApi != "false") {
   // Intentar parsear el string de fecha a DateTime
   if (DateTime.TryParse(fechaApi, out fechaNueva)) {
       // Establecer la nueva fecha si el parseo fue exitoso
       Set<DateTime>("FechaAperturaNueva", fechaNueva);
   }
}

if (XStudioUsuarios != "false") {
   // Intentar parsear el string a int
   if (int.TryParse(XStudioUsuarios, out XStudioUsuariosInt)) {
       // Establecer el nuevo valor si el parseo fue exitoso
       Set<int>("XStudioUsuariosInt", XStudioUsuariosInt);
   }
}

if (ExpectedRevenue != "false") {
   // Intentar parsear el string a int
   if (int.TryParse(ExpectedRevenue, out ExpectedRevenueInt)) {
       // Establecer el nuevo valor si el parseo fue exitoso
       Set<int>("ExpectedRevenueInt", ExpectedRevenueInt);
   }
}

return true;
 

Show all comments

I have a parameter within my business process that is a text, named UserName. On the other hand, I have an AddData that has a Lookup called CreatedBy. I need to relate the user name to the user name of this Lookup. That is, if the user name exists in the lookup, I assign this value to it.

Like 0

Like

1 comments

Greetings,
 

You can implement this using a parameter in the business process.


Below, I have provided an example of such an implementation. Please note that this is an example implementation, and you will need to adapt the business process to fit your business idea.




In my case, I pass a user as a parameter who is "TestDocum"; in this case, the process will follow the path to True.


If I pass another value, such as "Ser," the process will follow the path to False and terminate.


I hope this example helps you implement your business idea.
 

Best regards, 

Orkhan

Show all comments

Hello Community,

 

            I have created a business process using a script element that relies on "Newtonsoft.Json.Linq". 

 

 

Scenario 1 : When I add the business process to a custom package, it works perfectly. As shown in below Image

 

#Issue

Scenario 2 : When I add the business process to my app package "UsrG***", it throws an error during publishing due to the Linq dependency.

 

Let me know if you need any more adjustments!

 

Regards,

Ajay K

 

 

Like 0

Like

2 comments
Best reply

Hello,
 

This situation can occur if your custom "UsrG***" package has the "Compile into a separate assembly" attribute.

Compile

When converting a package to assembly package (AP), transferring a schema with code to a AP, or creating a version of a compiled process, the compilation error "The type or namespace cannot be found" occurs if the code uses types from external libraries located in other packages.
To solve your problem, deselect the "Compile into a separate assembly" checkbox for your package and recompile. This should solve the problem.

remove parameter
 

Thank you.

Hello,
 

This situation can occur if your custom "UsrG***" package has the "Compile into a separate assembly" attribute.

Compile

When converting a package to assembly package (AP), transferring a schema with code to a AP, or creating a version of a compiled process, the compilation error "The type or namespace cannot be found" occurs if the code uses types from external libraries located in other packages.
To solve your problem, deselect the "Compile into a separate assembly" checkbox for your package and recompile. This should solve the problem.

remove parameter
 

Thank you.

Serhii Parfentiev,

Thank you.

Show all comments

Hello!

I'm trying to make an integration with a digital signature call "Firmamex" and I trying to use the code that they provide in their SDK in a business process but i have error messages that dont let me publish the script task. 

This are the errors 

 

And this is the source code of the process. I already try to put a return true; at the end of the script task but stills send me the error. 

 

I hope you can help me.

 

namespace Terrasoft.Core.Process
{
 
    using Newtonsoft.Json;
    using SignmageSDK;
    using SignmageSDKCore;
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Drawing;
    using System.Globalization;
    using System.Text;
    using System.Web;
    using Terrasoft.Common;
    using Terrasoft.Configuration;
    using Terrasoft.Core;
    using Terrasoft.Core.Configuration;
    using Terrasoft.Core.DB;
    using Terrasoft.Core.Entities;
    using Terrasoft.Core.Process;
    using Terrasoft.Core.Process.Configuration;
 
    #region Class: UsrfirmamexMethodsWrapper
 
    /// <exclude/>
    public class UsrfirmamexMethodsWrapper : ProcessModel
    {
 
        public UsrfirmamexMethodsWrapper(Process process)
            : base(process) {
            AddScriptTaskMethod("ScriptTask1Execute", ScriptTask1Execute);
        }
 
        #region Methods: Private
 
        private bool ScriptTask1Execute(ProcessExecutingContext context) {
            }
            public class Flow
                {
                    SignmageSDK.FirmamexServices signmageServices;
                    String base64;
                    String name;
 
                    public Flow(SignmageSDK.FirmamexServices signmageServices, String base64, String name)
                    {
                        this.signmageServices = signmageServices;
                        this.base64 = base64;
                        this.name = name;
                    }
 
                    public String request()
                    {
                        B64_doc b64_doc = new B64_doc { name = name, data = base64 };
 
                        JObject flujoEjemplo = JObject.FromObject(new
                        {
                            b64_doc = b64_doc,
                            stickers = new object[] {
                                new {
                                    authority = "SAT",
                                    stickerType = "line",
                                    dataType = "rfc",
                                    data = "ARCX9012226P8",
                                    imageType = "hash",
                                    email = "jhon@gmail.com",
                                    page = "0",
                                    rect = new Rect { lx = 226.45f, ly = 355.25f, tx = 397.75f, ty = 413.85f }
                                }
                            },
                            workflow = new object[] {
                                new {
                                    data = "ARCX9012226P8"
                                }
                            },
                            app2 = true
                        });
 
                        String flujoParams = flujoEjemplo.ToString(Formatting.None);
                        return signmageServices.request(flujoParams);
                    }
                }
            };
        }
 
        #endregion
 
    }
 
    #endregion
 
}
Like 0

Like

2 comments

Hello Laura,
Thank you for your question.

I have some updates regarding you issue. 

First of all, indeed the generated code contains errors in lines 88 and 92 due to #endregion directives are being set in the wrong place.
1

Secondly, if you have a script task in your business process you might want to return a bool value inside it because the body of the script task if actually a body of a generated method (in your case ScriptTask1Execute).


Thirdly, it is impossible from my side to verify implementation of third-party code so i am unable to state that the code you provided will work. 

Lastly, if you have multiple versions of your business process that contain compilation errors, it is recommended to either correct them in all versions or delete them in the Configuration section of your application.

Hello Yevhenii Grytsiuk,

 

After the comments you left me, I have made some changes.

I have tried to place a return bool but every time I place it I get another error, so I have omitted it in order to be able to test if the script works. 
However, despite my attempts I still cannot remove this error "Type or namespace definition, or end-of-file expected"
It doesn't allow me to move the #endregion around, and even if I move the brackets it leaves it the same. In fact, that part is placed automatically when publishing the script, so I don't know how to move it so that I can stop having the error. 
If you have any idea on how to move it to remove the error, I would greatly appreciate it if you shared it with me.

Show all comments

Hello!

 

I'm trying to make an integration with a digital signature call "Firmamex" and I trying to use the code that they provide in their SDK in a business process but i have error messages that dont let me publish the script task. 

 

This are the errors 

 

 

And this is the code 

 

}
public class Flow
   {
       SignmageSDK.FirmamexServices signmageServices;
       String base64;
       String name;

       public Flow(SignmageSDK.FirmamexServices signmageServices, String base64, String name)
       {
           this.signmageServices = signmageServices;
           this.base64 = base64;
           this.name = name;
       }

       public String request()
       {
           B64_doc b64_doc = new B64_doc { name = name, data = base64 };

           JObject flujoEjemplo = JObject.FromObject(new
           {
               b64_doc = b64_doc,
               stickers = new object[] {
                   new {
                       authority = "SAT",
                       stickerType = "line",
                       dataType = "rfc",
                       data = "ARCX9012226P8",
                       imageType = "hash",
                       email = "jhon@gmail.com",
                       page = "0",
                       rect = new Rect { lx = 226.45f, ly = 355.25f, tx = 397.75f, ty = 413.85f }
                   }
               },
               workflow = new object[] {
                   new {
                       data = "ARCX9012226P8"
                   }
               },
               app2 = true
           });

           String flujoParams = flujoEjemplo.ToString(Formatting.None);
           return signmageServices.request(flujoParams);
       }
   }
};

 

I hope you can help me  to understand why I have that erros, please. 

Like 0

Like

2 comments

Hello, Laura.
Thank you for you question.

Unfortunately, it's hard to understand the source of the problem without proper context. Could you please provide me with the schema of your business process? This would greatly assist me in understanding the situation better and allow me to offer you effective assistance.

Hello Yevhenii 

 

Yes. Here it is the schema of the business process 

 

namespace Terrasoft.Core.Process
{

    using Newtonsoft.Json;
    using SignmageSDK;
    using SignmageSDKCore;
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Drawing;
    using System.Globalization;
    using System.Text;
    using System.Web;
    using Terrasoft.Common;
    using Terrasoft.Configuration;
    using Terrasoft.Core;
    using Terrasoft.Core.Configuration;
    using Terrasoft.Core.DB;
    using Terrasoft.Core.Entities;
    using Terrasoft.Core.Process;
    using Terrasoft.Core.Process.Configuration;

    #region Class: UsrfirmamexMethodsWrapper

    /// <exclude/>
    public class UsrfirmamexMethodsWrapper : ProcessModel
    {

        public UsrfirmamexMethodsWrapper(Process process)
            : base(process) {
            AddScriptTaskMethod("ScriptTask1Execute", ScriptTask1Execute);
        }

        #region Methods: Private

        private bool ScriptTask1Execute(ProcessExecutingContext context) {
            }
            public class Flow
                {
                    SignmageSDK.FirmamexServices signmageServices;
                    String base64;
                    String name;
            
                    public Flow(SignmageSDK.FirmamexServices signmageServices, String base64, String name)
                    {
                        this.signmageServices = signmageServices;
                        this.base64 = base64;
                        this.name = name;
                    }
            
                    public String request()
                    {
                        B64_doc b64_doc = new B64_doc { name = name, data = base64 };
            
                        JObject flujoEjemplo = JObject.FromObject(new
                        {
                            b64_doc = b64_doc,
                            stickers = new object[] {
                                new {
                                    authority = "SAT",
                                    stickerType = "line",
                                    dataType = "rfc",
                                    data = "ARCX9012226P8",
                                    imageType = "hash",
                                    email = "jhon@gmail.com",
                                    page = "0",
                                    rect = new Rect { lx = 226.45f, ly = 355.25f, tx = 397.75f, ty = 413.85f }
                                }
                            },
                            workflow = new object[] {
                                new {
                                    data = "ARCX9012226P8"
                                }
                            },
                            app2 = true
                        });
            
                        String flujoParams = flujoEjemplo.ToString(Formatting.None);
                        return signmageServices.request(flujoParams);
                    }
                }
            };
        }

        #endregion

    }

    #endregion

}

 

thank you for your help.

Show all comments

Greetings Community,

 

     Could someone provide me with references for Script Task queries related to CRUD operations on Creatio objects?

 

      Are there any examples or references available for sample scripts and C# functions regarding the Script Task element suitable for beginners?

Like 0

Like

2 comments

Hello,

 

As the first step, we recommend you to check our Academy article on Script Task process element that includes both instructions and examples of working with it. You can also use Academy and Community for searching examples of implementation of some more specific requests using the key words.

https://academy.creatio.com/docs/8.x/no-code-customization/bpm-tools/pr…

Hello Mira,

 

Thank you for your reply. I have reviewed the Academy article on the Script Task Process element. Also, executed on Creatio platform.

 

I am now interested in learning more about what we can accomplish with the Script Task element. Is there any additional information or examples available for Script element? 

 

regards, 

Ajay

Show all comments

Hello community,

I'm interested in utilizing the Script element within Creatio. Where can I find reference materials or code samples for C#?

 

Additionally, is there a platform available to compile C# code snippets before directly uploading them to the Creatio Platform (in the Script Task Element)?

Like 0

Like

7 comments

Hello,

 

All available examples of using the code in the script task element can be found here. As for checking the C# code - there is no such platform for business processes script tasks. You can create a code in Visual Studio and check if it works. Then, using the provided article, implement the same functionality in the business process script task.

Is it also possible to create your Standard source code and call those from a script task?  Similar to Process to calculate actual working time in projects on schedule?  

Oleg Drobina,

Thanks for your response. Is it feasible to import Terrasoft packages into Visual Studio? If yes, could you provide the steps to do so ?

keith schmitt,

 

as in OOP you can create an instance of a class and use its methods in the logic of a business process. Use Terrasoft.Configuration in the business process (add it to the process usings in the process settings) and create an instance of your class as SomeClass nameOfTheInstance = new SomeClass().

Ajay,

 

You can enable development in the file system as described here and there won't be a need to manually import packages in the Visual Studio. You will be able to review the code and apply changes to it.

Oleg Drobina,

Is there any video reference available?

Ajay,

 

I'm afraid we don't have it, but I will ask our Academy team if they can create such a video tutorial. Thank you for this suggestion!

Show all comments

Is it possible to set the value of a System setting which has the "Save value for current user" setting enabled for a specified user from C# code, e.g. from a script task? I've found the below code for setting a System setting, but presume that if the checkbox for the above is selected, then it will only set the value for the current user (or the System User if running in the system context):

var settingCode = Get<string>("UsrSystemSettingCode");
var value = Get<string>("UsrSettingValue");
Terrasoft.Core.Configuration.SysSettings.SetValue(UserConnection, settingCode, value);
return true;

 

We need to be able to set the per-user system setting for a specific user (determined by data in the BP in our case) but looking at the (always hard to find) API documentation, it doesn't seem like there's an overloaded version of SetValue that allows you to do so as a specified user - except possibly one that is marked as being deprecated in a much older version:

 

Like 0

Like

3 comments

Anybody have any info on this?

Does anyone have any other methods for managing per-user system settings in Creatio? It seems like there aren't a lot of options besides setting them in JS code when a user does a given action, but then that feels like it defeats some of the purpose of system settings being that the value doesn't have to be calculated every time a user does something, and also means it can't reliably be used for tasks like setting a default field value on an entity.

Contemplating using this methodology for running code when a user logs in to set it, hopefully it will work. Would be nice to have some clean way of doing it though, especially since we don't really need to be calculating it every time a user logs in but just when certain data changes: https://customerfx.com/article/executing-code-in-creatio-application-an…

Show all comments