How can I run a process from JS code (Schema Page)

Dear colleguagues

 

I need to run a process when create a new record, in this case invoke it from onEntityInitialized method just in case is a new record or a copy from another (this.isAddMode() || this.isCopyMode())

 

But don't know how to call a process from there, and how to pass parameters, is it possible?

 

Thanks in advance

Like 0

Like

3 comments
Best reply

Hi Julio,

 

You can use this article as a reference on how to trigger the process from the client and pass process parameters to the process.

 

As for calling the process upon creating a new record - onEntityInitialized is not a good choice here since the process call will be triggered once the page is loaded for adding a new record, but not once all the data on the page is specified and the record should be saved. In our case it's better to use save function and overwrite its logic. For example in a following manner:

 

1) We have a UsrTestJSON object which is a section in the system and has UsrTestJSON1Page as an edit page.

 

2) UsrTestJSON object has following columns:

 

UsrTransType - Text (250 characters) data type column

UsrPolicyNumber - Text (500 characters) data type column

UsrTransTime - Time data type column

UsrTransDate - Date data type column

3) We need to call the custom process called "Test JSON page process" with the following schema once the record is saved upon creation:

Please note that the process code is Process_20340ad and the process parameter codes should be the same as process parameter names (as an example please see UsrTransType parameter declaration).

 

4) Add the following code to the UsrTestJSON1Page schema:

define("UsrTestJSON1Page", ["ProcessModuleUtilities"], function(ProcessModuleUtilities) {
	return {
		entitySchemaName: "UsrTestJSON",
		attributes: {},
		modules: /**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,
		details: /**SCHEMA_DETAILS*/{
			"Files": {
				"schemaName": "FileDetailV2",
				"entitySchemaName": "UsrTestJSONFile",
				"filter": {
					"masterColumn": "Id",
					"detailColumn": "UsrTestJSON"
				}
			}
		}/**SCHEMA_DETAILS*/,
		businessRules: /**SCHEMA_BUSINESS_RULES*/{}/**SCHEMA_BUSINESS_RULES*/,
		methods: {
			callCustomProcess: function() {
                var usrTransType = this.get("UsrTransType");
				var usrPolicyNumber = this.get("UsrPolicyNumber");
				var usrTransDate = this.get("UsrTransDate");
				var usrTransTime = this.get("UsrTransTime");
                var args = {
                    sysProcessName: "Process_20340ad",
                    parameters: {
                        UsrTransType: usrTransType,
						UsrPolicyNumber: usrPolicyNumber,
						UsrTransDate: usrTransDate,
						UsrTransTime: usrTransTime
                    }
                };
                ProcessModuleUtilities.executeProcess(args);
            },
			save: function(){
				this.callParent(arguments);
				if (this.isAddMode()){
					this.console.log("Adding mode!!!");
					this.callCustomProcess();
				} else if (this.isCopyMode()){
					this.console.log("Copy mode!!!");
				} else if (this.isEditMode()){
					this.console.log("Edit mode!!!");
				} else {
					this.console.log("NOT EDIT, NOT COPY, NOT ADD!!!");
				}
			},
			onUsrTestJSONPageButtonClick: function(){
				this.save();
			}
		},
		dataModels: /**SCHEMA_DATA_MODELS*/{}/**SCHEMA_DATA_MODELS*/,
		diff: /**SCHEMA_DIFF*/[
			{
                "operation": "insert",
                "parentName": "ActionButtonsContainer",
                "propertyName": "items",
                "name": "UsrTestJSONPageButton",
                "values": {
                    itemType: Terrasoft.ViewItemType.BUTTON,
                    caption: { bindTo: "Resources.Strings.UsrTestJSONPageButtonCaption" },
                    click: { bindTo: "onUsrTestJSONPageButtonClick" },
                    "layout": {
                        "column": 1,
                        "row": 6,
                        "colSpan": 1
                    }
                }
            },
			{
				"operation": "insert",
				"name": "UsrTransTypec0a98c8f-acb0-4d1f-9333-94ba13a0abe4",
				"values": {
					"layout": {
						"colSpan": 24,
						"rowSpan": 1,
						"column": 0,
						"row": 0,
						"layoutName": "ProfileContainer"
					},
					"bindTo": "UsrTransType"
				},
				"parentName": "ProfileContainer",
				"propertyName": "items",
				"index": 0
			},
			{
				"operation": "insert",
				"name": "UsrPolicyNumber9a8b5c79-6a4f-4326-ab8e-d7c471ebc2a5",
				"values": {
					"layout": {
						"colSpan": 12,
						"rowSpan": 1,
						"column": 0,
						"row": 0,
						"layoutName": "Header"
					},
					"bindTo": "UsrPolicyNumber"
				},
				"parentName": "Header",
				"propertyName": "items",
				"index": 0
			},
			{
				"operation": "insert",
				"name": "UsrTransDate2bfe7bc7-21d7-4024-8809-919959aa5eaa",
				"values": {
					"layout": {
						"colSpan": 12,
						"rowSpan": 1,
						"column": 0,
						"row": 1,
						"layoutName": "Header"
					},
					"bindTo": "UsrTransDate"
				},
				"parentName": "Header",
				"propertyName": "items",
				"index": 1
			},
			{
				"operation": "insert",
				"name": "UsrTransTime7cede060-4f2c-406c-a74f-1abd5679848c",
				"values": {
					"layout": {
						"colSpan": 12,
						"rowSpan": 1,
						"column": 12,
						"row": 1,
						"layoutName": "Header"
					},
					"bindTo": "UsrTransTime"
				},
				"parentName": "Header",
				"propertyName": "items",
				"index": 2
			},
			{
				"operation": "insert",
				"name": "NotesAndFilesTab",
				"values": {
					"caption": {
						"bindTo": "Resources.Strings.NotesAndFilesTabCaption"
					},
					"items": [],
					"order": 0
				},
				"parentName": "Tabs",
				"propertyName": "tabs",
				"index": 0
			},
			{
				"operation": "insert",
				"name": "Files",
				"values": {
					"itemType": 2
				},
				"parentName": "NotesAndFilesTab",
				"propertyName": "items",
				"index": 0
			},
			{
				"operation": "insert",
				"name": "NotesControlGroup",
				"values": {
					"itemType": 15,
					"caption": {
						"bindTo": "Resources.Strings.NotesGroupCaption"
					},
					"items": []
				},
				"parentName": "NotesAndFilesTab",
				"propertyName": "items",
				"index": 1
			},
			{
				"operation": "insert",
				"name": "Notes",
				"values": {
					"bindTo": "Notes",
					"dataValueType": 1,
					"contentType": 4,
					"layout": {
						"column": 0,
						"row": 0,
						"colSpan": 24
					},
					"labelConfig": {
						"visible": false
					},
					"controlConfig": {
						"imageLoaded": {
							"bindTo": "insertImagesToNotes"
						},
						"images": {
							"bindTo": "NotesImagesCollection"
						}
					}
				},
				"parentName": "NotesControlGroup",
				"propertyName": "items",
				"index": 0
			},
			{
				"operation": "merge",
				"name": "ESNTab",
				"values": {
					"order": 1
				}
			}
		]/**SCHEMA_DIFF*/
	};
});

So the main idea here is calling callCustomProcess method upon record saving (this.isAddMode()):

save: function(){
				this.callParent(arguments);
				if (this.isAddMode()){
					this.console.log("Adding mode!!!");
					this.callCustomProcess();
				}

And you bind page data to the process using args object parameters:

var args = {
                    sysProcessName: "Process_20340ad",
                    parameters: {
                        UsrTransType: usrTransType,
						UsrPolicyNumber: usrPolicyNumber,
						UsrTransDate: usrTransDate,
						UsrTransTime: usrTransTime
                    }
                };

usrTransType, usrPolicyNumber, usrTransDate and usrTransTime variables are received from the page before saving the record (using this.get method).

 

So you need to develop the logic similar to described above using your own object, process and page schema. As a result the process will return the data specified when creating a new record:

Best regards,

Oscar

Hi Julio,

 

You can use this article as a reference on how to trigger the process from the client and pass process parameters to the process.

 

As for calling the process upon creating a new record - onEntityInitialized is not a good choice here since the process call will be triggered once the page is loaded for adding a new record, but not once all the data on the page is specified and the record should be saved. In our case it's better to use save function and overwrite its logic. For example in a following manner:

 

1) We have a UsrTestJSON object which is a section in the system and has UsrTestJSON1Page as an edit page.

 

2) UsrTestJSON object has following columns:

 

UsrTransType - Text (250 characters) data type column

UsrPolicyNumber - Text (500 characters) data type column

UsrTransTime - Time data type column

UsrTransDate - Date data type column

3) We need to call the custom process called "Test JSON page process" with the following schema once the record is saved upon creation:

Please note that the process code is Process_20340ad and the process parameter codes should be the same as process parameter names (as an example please see UsrTransType parameter declaration).

 

4) Add the following code to the UsrTestJSON1Page schema:

define("UsrTestJSON1Page", ["ProcessModuleUtilities"], function(ProcessModuleUtilities) {
	return {
		entitySchemaName: "UsrTestJSON",
		attributes: {},
		modules: /**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,
		details: /**SCHEMA_DETAILS*/{
			"Files": {
				"schemaName": "FileDetailV2",
				"entitySchemaName": "UsrTestJSONFile",
				"filter": {
					"masterColumn": "Id",
					"detailColumn": "UsrTestJSON"
				}
			}
		}/**SCHEMA_DETAILS*/,
		businessRules: /**SCHEMA_BUSINESS_RULES*/{}/**SCHEMA_BUSINESS_RULES*/,
		methods: {
			callCustomProcess: function() {
                var usrTransType = this.get("UsrTransType");
				var usrPolicyNumber = this.get("UsrPolicyNumber");
				var usrTransDate = this.get("UsrTransDate");
				var usrTransTime = this.get("UsrTransTime");
                var args = {
                    sysProcessName: "Process_20340ad",
                    parameters: {
                        UsrTransType: usrTransType,
						UsrPolicyNumber: usrPolicyNumber,
						UsrTransDate: usrTransDate,
						UsrTransTime: usrTransTime
                    }
                };
                ProcessModuleUtilities.executeProcess(args);
            },
			save: function(){
				this.callParent(arguments);
				if (this.isAddMode()){
					this.console.log("Adding mode!!!");
					this.callCustomProcess();
				} else if (this.isCopyMode()){
					this.console.log("Copy mode!!!");
				} else if (this.isEditMode()){
					this.console.log("Edit mode!!!");
				} else {
					this.console.log("NOT EDIT, NOT COPY, NOT ADD!!!");
				}
			},
			onUsrTestJSONPageButtonClick: function(){
				this.save();
			}
		},
		dataModels: /**SCHEMA_DATA_MODELS*/{}/**SCHEMA_DATA_MODELS*/,
		diff: /**SCHEMA_DIFF*/[
			{
                "operation": "insert",
                "parentName": "ActionButtonsContainer",
                "propertyName": "items",
                "name": "UsrTestJSONPageButton",
                "values": {
                    itemType: Terrasoft.ViewItemType.BUTTON,
                    caption: { bindTo: "Resources.Strings.UsrTestJSONPageButtonCaption" },
                    click: { bindTo: "onUsrTestJSONPageButtonClick" },
                    "layout": {
                        "column": 1,
                        "row": 6,
                        "colSpan": 1
                    }
                }
            },
			{
				"operation": "insert",
				"name": "UsrTransTypec0a98c8f-acb0-4d1f-9333-94ba13a0abe4",
				"values": {
					"layout": {
						"colSpan": 24,
						"rowSpan": 1,
						"column": 0,
						"row": 0,
						"layoutName": "ProfileContainer"
					},
					"bindTo": "UsrTransType"
				},
				"parentName": "ProfileContainer",
				"propertyName": "items",
				"index": 0
			},
			{
				"operation": "insert",
				"name": "UsrPolicyNumber9a8b5c79-6a4f-4326-ab8e-d7c471ebc2a5",
				"values": {
					"layout": {
						"colSpan": 12,
						"rowSpan": 1,
						"column": 0,
						"row": 0,
						"layoutName": "Header"
					},
					"bindTo": "UsrPolicyNumber"
				},
				"parentName": "Header",
				"propertyName": "items",
				"index": 0
			},
			{
				"operation": "insert",
				"name": "UsrTransDate2bfe7bc7-21d7-4024-8809-919959aa5eaa",
				"values": {
					"layout": {
						"colSpan": 12,
						"rowSpan": 1,
						"column": 0,
						"row": 1,
						"layoutName": "Header"
					},
					"bindTo": "UsrTransDate"
				},
				"parentName": "Header",
				"propertyName": "items",
				"index": 1
			},
			{
				"operation": "insert",
				"name": "UsrTransTime7cede060-4f2c-406c-a74f-1abd5679848c",
				"values": {
					"layout": {
						"colSpan": 12,
						"rowSpan": 1,
						"column": 12,
						"row": 1,
						"layoutName": "Header"
					},
					"bindTo": "UsrTransTime"
				},
				"parentName": "Header",
				"propertyName": "items",
				"index": 2
			},
			{
				"operation": "insert",
				"name": "NotesAndFilesTab",
				"values": {
					"caption": {
						"bindTo": "Resources.Strings.NotesAndFilesTabCaption"
					},
					"items": [],
					"order": 0
				},
				"parentName": "Tabs",
				"propertyName": "tabs",
				"index": 0
			},
			{
				"operation": "insert",
				"name": "Files",
				"values": {
					"itemType": 2
				},
				"parentName": "NotesAndFilesTab",
				"propertyName": "items",
				"index": 0
			},
			{
				"operation": "insert",
				"name": "NotesControlGroup",
				"values": {
					"itemType": 15,
					"caption": {
						"bindTo": "Resources.Strings.NotesGroupCaption"
					},
					"items": []
				},
				"parentName": "NotesAndFilesTab",
				"propertyName": "items",
				"index": 1
			},
			{
				"operation": "insert",
				"name": "Notes",
				"values": {
					"bindTo": "Notes",
					"dataValueType": 1,
					"contentType": 4,
					"layout": {
						"column": 0,
						"row": 0,
						"colSpan": 24
					},
					"labelConfig": {
						"visible": false
					},
					"controlConfig": {
						"imageLoaded": {
							"bindTo": "insertImagesToNotes"
						},
						"images": {
							"bindTo": "NotesImagesCollection"
						}
					}
				},
				"parentName": "NotesControlGroup",
				"propertyName": "items",
				"index": 0
			},
			{
				"operation": "merge",
				"name": "ESNTab",
				"values": {
					"order": 1
				}
			}
		]/**SCHEMA_DIFF*/
	};
});

So the main idea here is calling callCustomProcess method upon record saving (this.isAddMode()):

save: function(){
				this.callParent(arguments);
				if (this.isAddMode()){
					this.console.log("Adding mode!!!");
					this.callCustomProcess();
				}

And you bind page data to the process using args object parameters:

var args = {
                    sysProcessName: "Process_20340ad",
                    parameters: {
                        UsrTransType: usrTransType,
						UsrPolicyNumber: usrPolicyNumber,
						UsrTransDate: usrTransDate,
						UsrTransTime: usrTransTime
                    }
                };

usrTransType, usrPolicyNumber, usrTransDate and usrTransTime variables are received from the page before saving the record (using this.get method).

 

So you need to develop the logic similar to described above using your own object, process and page schema. As a result the process will return the data specified when creating a new record:

Best regards,

Oscar

Hi Julio,



You can trigger a business process from Client JS code using the ProcessModuleUtilities module. You can inject it as a dependency in a Client schema and call the executeProcess(args) method to call a business process. Business process parameters can be set in the parameters attribute inside the argument you pass to the executeProcess method. Request you to go through this academy link for more information.



If your use case is to trigger a business process 'after' a new record is created, there are a few ways of doing it. You could use the 'Record created' trigger in the Business process designer. Or you can also choose to do it from the service side by listening to entity events on the specific section/object. You can get more details in this academy link.



Thanks,

Shrikanth

M Shrikanth,

Thank you very much

Show all comments