onInitialized on Mobile Creatio

Hello, i want to ask about how to implement code on life cycle Initialized on Mobile Creatio. On Web version, i can use onInitiliazed function, but on mobile i didnt find any possible way to do so. 

In my case, i need to get current month everytime user open the page. 

Anyone can help? 

Like 0

Like

3 comments

Hello,

 

As was stated here, the analog of the onEntityInitialized method from the desktop version is the onLoadRecord method in the mobile application. It should be overridden in the Controller of the corresponded edit page of the mobile application. 

Oleg Drobina,

Hi Oleg Drobina, thanks for answer my question. 
Can i have example of onLoadRecord code, i still have no idea how to use it. 
Thanks

Yosua Aleksander Thanos, 

Hello! 

Here is an example of the controller for the PharmaMobileActivityEditPage, you may modify it according to your business task:

/* globals Activity: false */
/* globals ActivityCategory: false */
Terrasoft.LastLoadedPageData = {
	controllerName: "Terrasoft.configuration.controller.PharmaMobileActivityEditPage",
	viewXType: "fieldforceactivityeditpageview"
};
 
Ext.define("Terrasoft.configuration.controller.PharmaMobileActivityEditPage", {
	alternateClassName: "PharmaMobileActivityEditPage.Controller",
	extend: "FieldForceActivityEditPage.Controller",
 
	statics: {
		Model: Activity
	},
 
	/**
	 * @private
	 */
	createPromotedProducts: function(config) {
		var record = config.records.pop();
		if (!record) {
			Ext.callback(config.success, config.scope);
			return;
		}
		var product = record.get("Product");
		if (!product) {
			this.createPromotedProducts(config);
			return;
		}
		var failureFn = function(exception) {
			Ext.callback(config.failure, config.scope, [exception]);
		};
		var modelName = "ActivityPromProduct";
		var model = Ext.ClassManager.get(modelName);
		model.createWithDefaultValues(function(newRecord) {
			newRecord.set("Activity", config.activityId);
			newRecord.set("Product", product);
			newRecord.save({
				isCancelable: false,
				queryConfig: Ext.create("Terrasoft.QueryConfig", {
					modelName: modelName,
					columns: ["Activity", "Product"]
				}),
				success: function() {
					this.createPromotedProducts(config);
				},
				failure: failureFn
			}, this);
		}, failureFn, this, {isCancelable: false});
	},
 
	/**
	 * @private
	 */
	getPromotedProducts: function(config) {
		var filters = Ext.create("Terrasoft.Filter", {
			property: "Contact",
			value: config.contactId
		});
		var columns = ["Product"];
		Terrasoft.DataUtils.loadRecords({
			modelName: "PromotedProduct",
			filters: filters,
			columns: columns,
			success: function(records) {
				Ext.callback(config.success, config.scope, [records]);
			},
			failure: function(exception) {
				Ext.callback(config.failure, config.scope, [exception]);
			},
			scope: this
		});
	},
 
	/**
	 * @private
	 */
	createNosologiesByProducts: function(config) {
		var filters = Ext.create("Terrasoft.Filter", {
			property: "Product",
			funcType: Terrasoft.FilterFunctions.In,
			funcArgs: config.productIds
		});
		var failureFn = function(exception) {
			Ext.callback(config.failure, config.scope, [exception]);
		};
		Terrasoft.DataUtils.loadRecords({
			modelName: "NosologyInProduct",
			filters: filters,
			columns: ["Nosology"],
			success: function(records) {
				this.createNosologyInActivity({
					activityId: config.activityId,
					records: records,
					addedNosologies: [],
					success: function() {
						Ext.callback(config.success, config.scope);
					},
					failure: failureFn,
					scope: this
				});
			},
			failure: failureFn,
			scope: this
		});
	},
 
	/**
	 * @private
	 */
	createNosologyInActivity: function(config) {
		var record = config.records.pop();
		if (!record) {
			Ext.callback(config.success, config.scope);
			return;
		}
		var nosology = record.get("Nosology");
		var nosologyId = nosology ? nosology.getId() : null;
		if (nosologyId === null || Ext.Array.contains(config.addedNosologies, nosologyId)) {
			this.createNosologyInActivity(config);
			return;
		}
		var failureFn = function(exception) {
			Ext.callback(config.failure, config.scope, [exception]);
		};
		var modelName = "NosologyInActivity";
		var model = Ext.ClassManager.get(modelName);
		model.createWithDefaultValues(function(newRecord) {
			newRecord.set("Activity", config.activityId);
			newRecord.set("Nosology", nosology);
			newRecord.save({
				isCancelable: false,
				queryConfig: Ext.create("Terrasoft.QueryConfig", {
					modelName: modelName,
					columns: ["Activity", "Nosology"]
				}),
				success: function() {
					config.addedNosologies.push(nosologyId);
					this.createNosologyInActivity(config);
				},
				failure: failureFn
			}, this);
		}, failureFn, this, {isCancelable: false});
	},
 
	/**
	 * @private
	 */
	fillVisitToDoctorDetails: function(config) {
		var failureFn = function(exception) {
			Ext.callback(config.failure, config.scope, [exception]);
		};
		this.getPromotedProducts({
			contactId: config.contactId,
			success: function(promotedProducts) {
				this.createPromotedProducts({
					activityId: config.activityId,
					records: Ext.clone(promotedProducts),
					success: function() {
						var productIds = [];
						for (var i = 0, ln = promotedProducts.length; i < ln; i++) {
							var productId = promotedProducts[i].get("Product.Id");
							if (productId) {
								productIds.push(productId);
							}
						}
						if (productIds.length === 0) {
							Ext.callback(config.success, config.scope);
							return;
						}
						this.createNosologiesByProducts({
							activityId: config.activityId,
							productIds: productIds,
							success: function() {
								Ext.callback(config.success, config.scope);
							},
							failure: failureFn,
							scope: this
						});
					},
					failure: failureFn,
					scope: this
				});
			},
			failure: failureFn,
			scope: this
		});
	},
 
	/**
	 * @inheritdoc
	 * @protected
	 * @overridden
	 */
	copyProductsFromAccount: function(config) {
		var activity = config.activity;
		var categoryId = activity.get("ActivityCategory.Id");
		if (categoryId === Terrasoft.Configuration.ActivityCategory.PharmacyVisit) {
			this.callParent(arguments);
		} else {
			Ext.callback(config.success, config.scope);
		}
	},
 
	/**
	 * @inheritdoc
	 * @protected
	 * @overridden
	 */
	onLoadRecord: function(record) {
		var detailConfig = this.getDetailConfig();
		if (record.phantom && detailConfig && record.get("Type.Id") === Terrasoft.Configuration.ActivityTypes.Visit) {
			var categoryId;
			switch (detailConfig.parentColumnName) {
				case "Account":
					categoryId = Terrasoft.Configuration.ActivityCategory.PharmacyVisit;
					break;
				case "Contact":
					categoryId = Terrasoft.Configuration.ActivityCategory.DoctorVisit;
					break;
				default:
					categoryId = null;
					break;
			}
			if (categoryId) {
				var activityCategory = ActivityCategory.Store.getById(categoryId);
				record.set("ActivityCategory", activityCategory);
			}
		}
		this.callParent(arguments);
		var pageHistoryItem = this.getPageHistoryItem();
		var rawConfig = pageHistoryItem.getRawConfig();
		if (rawConfig.focusColumn) {
			setTimeout(function() {
				var field = this.getFieldByColumnName(rawConfig.focusColumn);
				if (!field) {
					return;
				}
				if ("getPicker" in field) {
					var picker = field.getPicker();
					picker.show();
				} else {
					field.focus();
				}
			}.bind(this), 50);
		}
	},
 
	/**
	 * @inheritdoc
	 * @protected
	 * @overridden
	 */
	completeDataSaving: function() {
		var args = arguments;
		var record = this.record;
		var categoryId = record.get("ActivityCategory.Id");
		var contactId = record.get("Contact.Id");
		if (this.isNewVisit && categoryId === Terrasoft.Configuration.ActivityCategory.DoctorVisit && contactId) {
			var activityId = record.getPrimaryColumnValue();
			this.fillVisitToDoctorDetails({
				activityId: activityId,
				contactId: contactId,
				success: function() {
					var parent = Terrasoft.configuration.controller.PharmaMobileActivityEditPage.superclass;
					parent.completeDataSaving.apply(this, args);
				},
				failure: function(exception) {
					Terrasoft.Mask.hide({force: true});
					Terrasoft.MessageBox.showException(exception);
				},
				scope: this
			});
		} else {
			this.callParent(args);
		}
	},
 
	/**
	 * @inheritdoc
	 * @protected
	 * @overridden
	 */
	getCategoryId: function() {
		var activityRecord = this.record;
		var category = activityRecord.get("ActivityCategory");
		return category ? category.get("Id") : null;
	}
 
});
Show all comments