Hello community:



I'm defining a rule inside the section code schema to remove spaces from a field value when the user tries completes the field "UsrTexto1". It is defined as follows:

methods: {
    cambioTexto1: function() {
        var vueltas = this.get("Vueltas");
        this.set("Vueltas",vueltas+1);
 
        var txt1 = this.get("UsrTexto1");
        if (txt1.includes(' ')) {
            var txt2 = txt1.replaceAll(' ','');
            this.set("UsrTexto1",txt2);
        }
    },
}

So when the field is modified it searches for spaces inside the text and removes them. This is an example of execution:

1) When the user types the text value

2) After the method is executed:

 

The problem is that the function is executed too many times. I've added a counter 'vueltas' to show how many times the function is called and here it is the result:

It doesn't make sense as I think that the method should be called exactly 2 times (1st when it removes the spaces, and 2nd when the system detects new changes on the field and now there are no spaces). The main problem is that the whole operation is slowed down because of the high number of calls.

 

How can I fix this?

 

Thanks in advance!

Like 0

Like

5 comments

Hello,

Can you please clarify how exactly the cambioTexto1 method is called?

Thank you!

The issue is that every change made to the text results in it firing the function again, plus, the changed value won't be read by the function on subsequent calls due to the timing is that the function firing and the value changing, which is why it's getting called so many times (and likely exceeding out the call stack max).

 

Instead if firing the value on the change, maybe fire it on the blur (when the user exits the control). To do this, remove the change attribute for the control and add this to the values block for the control in the diff:

"blur": {
    "bindTo": "cambioTexto1"
}

Or you could do it on save before using callParent.

 

Ryan

Oleg Drobina,

Hello Oleg,

In the section page there is a field called "Texto1" (with the code UsrTexto1). Inside the code schema of that section is the method that I provided earlier.

As you may see the method is called cambioTexto1, which is compose of cambio ("change" in Spanish) and Texto1 (the name of the field). It means that Creatio internally calls that function each time the value of that field is modified (with a built-in trigger I guess).

Therefore, the method is always called automatically, I don't call it manually.

Thanks for your interest!

Ryan Farley,

That makes sense,



I will try that tomorrow and check if it solves the problem



Thanks for you help!

Ryan Farley,

Hi again,

 

I've tried with the solution you provided but I haven't been able to fix the issue yet.

 

I also took a look at and older post where you submitted the same solution. I've tried to follow the implementation as you suggest. Here I share the current code:

{
	"operation": "insert",
	"name": "STRINGe5cdab8a-f59c-4c1c-aa90-c412e4c3e5ae",
	"values": {
		"layout": {
			"colSpan": 24,
			"rowSpan": 1,
			"column": 0,
			"row": 1,
			"layoutName": "ProfileContainer"
		},
		"bindTo": "UsrTexto1",
		"enabled": true,
		"blur": {
			"bindTo": "cambioTexto1"
		}
	},
	"parentName": "ProfileContainer",
	"propertyName": "items",
	"index": 1
},

Note: I have also removed the attributes part as you mentioned.

The problem is that when I try to modify a register or create a new one this happens:

The page displays blank content and, as you can see on the browser console at the right, there is an error related to an undefined value.

The messages you see before the error are traces I added to see the variable values:

console.log("Vueltas: " + this.get("Vueltas"));
- Vueltas: 0
 
console.log("Modificado: " + this.get("Modificado"));
- Modificado: false
 
console.log("Value read: " + this.get("UsrTexto1"));
- Value read: undefined

I have already read the documentation for the client schemas and I still have no clue how to solve it.

 

Regards.

Show all comments

Hi,

I have a requirement to fetch data from an external API. The call is pretty costly in terms of performance and the data size is pretty huge. The good thing is the data is relatively static and doesn't change too often. Also, the data is transient in nature. It needs to be used for some intermediate processing and need not be persisted in the BPM'Online database. Ideally, I would like to store this data in the Redis Cache and set an expiry of 3 hours.

Theoretically, it seems possible to access the Redis Cache and get/set the values from/into the cache through the Source Code Schema. I wanted to confirm if there are any recommended ways of doing it? Are there any C# wrappers/classes that are already built in BPM'Online that we can use to get/set/invalidate cache?

Thanks in advance for all the help...

Like 0

Like

4 comments

Dear Amanthena,

There is no possibility to write directly to the Redis cache from the configuration. However, you can write to the Application level cache, which is stored to the Redis. Please see this article to find more info on Application cache:

https://academy.bpmonline.com/documents/technic-sdk/7-13/recommendations-use-different-types-repositories

The access to the Application cache is through UserConnection. ApplicationCache is a dictionary and to read/write you need to do the following:

userConnection.ApplicationCache[«123”] = “qwe”

Hope you find it helpful!

Anastasia

Thank you for all the life-saving help, Anastasia!

Anastasia Botezat,

 

Hi Anastasia,



In your earlier comment, you give an example of how to store a String in the dictionary. Could you share a working code snippet of how we can cache C# objects inside it? 



Ref - https://community.creatio.com/questions/store-object-icachestore-sessio…;

Dear Shrikanth,

 

In order to store an object in Application cache you should serialize the object to string and save the string. Please find more information about serialization in the article by the link below:

 

https://stackoverflow.com/questions/2434534/serialize-an-object-to-string

 

Best regards,

Norton

Show all comments