Hello,

 

I need to call a code once a record gets created for the first time. This worked using the following:

handlers: /**SCHEMA_HANDLERS*/[
			{
        request: "crt.SaveRecordRequest",
        handler: async (request, next) => {

 

however what this does is execute the code for each attribute value change, which is not what is needed. How can I call this exactly once just when the record is created for the first time and that's it, without having to call it again for each save request? Thanks

 

Note: I have tried replacing SaveRecordRequest with CreateRecordRequest, however the code was not executed once saving, or on any save.

 

Best,

Mohamad

Like 0

Like

10 comments

You can use the CardState to see if the record is in add mode (record is being added, saved for first time) or edit mode:

const mode = await request.$context.CardMode;
if (mode === “add”) {
    //
}

If you need to call some code exactly once when a record is created, I'd suggest moving the whole logic to backend. Specifically EntityEventListener and implement OnInserting or OnInserted methods to call your logic before or after the record is saved

Ryan Farley,

Hey Ryan,

 

Thanks for the reply, however that didn't work. The CardMode returns undefined, and when inspecting it in developer tools (request.$context object) the value is always 'edit' , when inserting the first time or when updating. Is there anything else I can do to fix the issue? Thanks

 

Best,

Mohamad

Yurii Sokil,

Hey Yurii,

 

Thanks for the reply, I have tried moving the logic to backend, however I encountered some issues. The overloaded method OnInserted cannot be async, and therefore I cannot call APIs directly from that method.

There is another option to call asynchronously using this method https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platform/back-end-development/objects-business-logic#title-2173-11 . However that doesn't solve the problem as if there were any errors when executing the asynchronous code, the record gets saved normally without indicating errors. Its a fire and forget operation and I need something that prevents a record from being inserted if the API call failed. Is there any way I can achieve this? Thanks for help

 

Best,

Mohamad

Mohamad Salhani,

If all you're after is to set up an auto number column, you can use the new auto number column default value. See https://customerfx.com/article/working-with-autonumber-fields-in-creatio/

Ryan

Ryan Farley,

No, so basically I need to populate a field once a record is created, and the value comes from an external API that I have to call

Ryan Farley,

Thanks for the support, I was finally able to solve it by checking the createdOn and modifiedOn dates for the record and see if they are equal, this way I can identify if the record was added for the first time or not. 

Thanks again!

Hi Mohamad, 
You can use AsyncPump.Run() to call async methods synchronously in your event listener. Also you can override OnInserting rather than OnInserted so your logic is called before the record is actually saved. 

Yurii Sokil,

Hey Yuri,

 

Thanks for the reply! It did work however I have a question. How can I pass arguments to the method passed in AsyncPump.Run() ? 

I have this code, but I can't pass arguments to the method.

 

[EntityEventListener(SchemaName = "UsrPetolTest")]
public class CustomEntityEventListener : BaseEntityEventListener
{
    public override void OnInserting(object sender, EntityBeforeEventArgs e)
    {
        base.OnInserting(sender, e);
 
        var entity = (Entity)sender;
        var userConnection = entity.UserConnection;
 
        AsyncPump.Run(testing);
 
    }
 
    private async void testing()
    {
        try
        {

 

Best,

Mohamad

Show all comments

Hi,

I want to run a web service on combobox changed event.

What is the syntax of register the handler in the client module file? 

(What do I need to write in viewConfigDiff --> values to execute the handler on the change event?)

 

Thanks,

Smadar

Like 0

Like

2 comments
Best reply

You can see how to respond to the change event here: https://customerfx.com/article/responding-to-an-event-when-a-field-is-c…

Also, for calling the web service see here https://customerfx.com/article/calling-configuration-web-services-from-…

Ryan

You can see how to respond to the change event here: https://customerfx.com/article/responding-to-an-event-when-a-field-is-c…

Also, for calling the web service see here https://customerfx.com/article/calling-configuration-web-services-from-…

Ryan

Thanks! It solved my problem :)

Show all comments

Hi, I've got a page holding two new checkboxes. If the first checkbox (let's say "A") is marked, the second (let's call it "B") has to be unmarked and the other way around. I set the condition in the rules tab, in the page wizard, and each time I clicked on one of the boxes, the second became unavailable as it was projected. However, clicking on the labels of those boxes allowed for marking both of them! I thought I made a mistake and removed the condition.

Having known that both checkboxes are defined in diff array, I declared two schema attributes controlling if they are enabled/disabled. I also glued to the definition of checkboxes event-handlers in this way that each checkbox has its own click event-handler. Event handlers are defined in the section for methods.

Each event handler is responsible for controlling the state of the second checkbox if the first is marked/unmarked. And this time, it also works like a charm, but only when I click on checkboxes. Again when I click on labels of checkboxes, it's possible to mark both checkboxes at the same time. Moreover, it's impossible to handle click-events from these labels.

If it were "normal" js or ts I would handle that easily. Here, I'm running out of ideas. Could you advise me on how to achieve control on those labels, as well (to be precise, I need to have responsive labels to improve user experience)? What I've done wrong so far?

Like 0

Like

1 comments

Dear Duffy,

 

Thank you for submitting your question!

 

Could you please elaborate more on your question and possibly provide some screenshots?

 

Thank you!

 

Regards,

 

Danyil

Show all comments



Dear Community,

 

I am trying to copy values from a field and lookups to put it in the "Name" fields before saving.

I use the following code in the script task but I don't know how to get the value from a lookup:

Entity.Name = $"{Entity.Code } - {Entity.Description}";

Code being the lookup.



So if you create a record in a lookup it would go like this:

[Name][Code][Description]

[           ][ 001 ][Code for info]



The Name should automatically be filled with "001 - Code for info" after saving.

What is the correct way to set the script?

Thank you!

 

 

Kind regards,

Yosef

 

Like 0

Like

2 comments

Hi!

 

Just add on saving event in your lookup entity, and add a script

 

Entity.SetColumnValue("Name", string.Format("[{0}][{1}]", Entity.GetTypedColumnValue<string>("Code"), Entity.GetTypedColumnValue<string>("Descritpion"));

 

Dmytro Oliinyk,

 

 

Thank you but that didn't seem to work for me, this was the solution for me:

 

var name = Entity.GetColumnValue("Name");
var description = Entity.GetColumnValue("Description");
 
var esq = new EntitySchemaQuery(Entity.Schema);
esq.AddColumn("Code.Name");
 
var CodeEntity= esq. GetEntity(UserConnection, Entity.PrimaryColumnValue);
if (CodeEntity != null) {
 
	var columnUsrCodeName = CodeEntity .GetTypedColumnValue<string>("Code_Name");
 
	string fullName= $"{name}: {columnUsrCodeName } - {description}";
	Entity.SetColumnValue("Name", fullName);
}
return true;

Let me know if there's an easier way to do this.

 

 

Kind regards,

Yosef

Show all comments

Hi,

I would like to know how can i trigger 'someMethod' by adding, editing or removing something in my detail.

 

Like 1

Like

4 comments

Dear Pedro,

Please find the options to trigger your custom method:

adding:

you can override the addRecord method of BaseGridDetailV2 to launch your custom method along with parent realization.

editing:

You can create a new attribute on the page schema, which will trigger method "methodName" based on the changes in indicated columns:

"Probability": {
    // Determination of the column dependency.
    "dependencies": [
      {
        // Depends on the "Stage" column.
        "columns": [ "Stage" ],
        // The name of the handler method for the "Stage" column change.
        // setProbabilityByStage() method is defined  in methods property
        // of schema object.
        "methodName": "setProbabilityByStage"
      }
    ]
  }

delete:

you can override the basic deleteRecords method on the detail schema, so to run your custom method after, or before parent realization of the method.

Regards,

Anastasia

Anastasia Botezat,

 Hi,

I've tried to override "deleteRecords" method on my detail schema page, and didn't work, I think its because of package dependencies but I'm not sure.

Pedro Pinheiro,

The "deleteRecords" method does work on the detail schema. Please debug the code, so to narrow down the possible cause. Here is an instruction on the client side debug:

https://academy.bpmonline.com/documents/technic-sdk/7-13/client-code-debugging

Regards,

Anastasia

Anastasia Botezat, I manage to fix my problem using "onDelete" instead of the "deleteRecords" method.

Thanks for your response.

Show all comments

I have an requirement to change city lookup whenever zip code is changed so is there any event that will do my work?

Thanks

Like 0

Like

2 comments

If you have a ZIP code field or similar in City to filter it by, you can set up a business rule similar to this, with your field in place of Description:

If you require more complex logic, go to the edit page in the backend and add a dependency to the attributes section:

attributes: {
    "City": {
	dependencies: [
	    {
		columns: ["Zip"],
		methodName: "doSomething"
	    }
	]
    }
}

And include your logic in the doSomething method, which will be called every time Zip is changed.

Dear Agha,

Please check the example provided by Darian. For the simple business task it is recommended to use business rules. 

In case you need more complex logic, including if clause, or evaluation on Id, or any other logic, which cannot be implemented by business rules, please use attributes.

In order to add an attribute you need to go to Advanced settings --> create a new replacing module for your page --> add an attribute and save the schema --> clear browser cache. 

Please see articles on schema attributes:

https://academy.bpmonline.com/documents/technic-sdk/7-13/attributes-attributes-property

Regards,

Anastasia

Show all comments

I have  string text field, I want to pop up look up upon hitting [enter] or [tab] keys

Like 0

Like

1 comments

It will be hard to catch the [tab] click event. The problem is that the [tab] key is reserved for changing an active element in a browser.

The [Enter] key will be easy to catch. I would do the following:

define("ContactPageV2", [], function() {
	return {
		entitySchemaName: "Contact",
		attributes: {},
		modules: /**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,
		details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
		businessRules: /**SCHEMA_BUSINESS_RULES*/{}/**SCHEMA_BUSINESS_RULES*/,
		methods: {
			onEntityInitialized: function() {
				this.callParent(arguments);
			},
			onPhoneClick: function(e) {
				if (e && e.keyCode === 13) {
					console.log("show popup");
				}
			}
		},
		dataModels: /**SCHEMA_DATA_MODELS*/{}/**SCHEMA_DATA_MODELS*/,
		diff: /**SCHEMA_DIFF*/[
			{
				"operation": "merge",
				"name": "AccountPhone",
				"values": {
					"layout": {
						"colSpan": 24,
						"rowSpan": 1,
						"column": 0,
						"row": 4
					},
					"keyup": {
						"bindTo": "onPhoneClick"
					}
				}
			}
		]/**SCHEMA_DIFF*/
	};
});

 

Show all comments