Hi 

I would appreciate if someone could guide me how to read the value from a WiJob object, which has a lookup WiBuilding and WiBuilding has a column WiChargeRate. I added this as dependency in attributes, I can see teh value is there but I am unable to read it. Please see image below.

Like 0

Like

3 comments

Hello Waseem,



You can operate with value of the property of the JS object just by using the property name e.g. to get the "WiBuilding" value you should use "job.WiBuilding".  The value that you will get is the WiBuilding object.

The "value " property of the "WiBuilding" object stores the Id of the record in "WiBuilding" lookup (since the "WiBuilding" is the lookup). 



How to get object`s value from the database by it`s id:

https://academy.bpmonline.com/documents/technic-sdk/7-13/use-entitysche…

Best regards,

Alex

Thank you Alex, you are right I do get the value of the WiBuilding by writing Job.WiBuilding or Job.WiBuilding.value. I am struggling with the next layer which is the WiBuilding.WiChargeRate (displaying 125 in the above image). I tried Job.WiBuilding.WiChargeRate but it does not give me the value of 125. Should I try Job.WiBuilding.WiChargeRate.value. 

In regards to Entity Schema, I wrote the following ESQ and I could get the value to display in the pop up but I could not read it in to variable to do some calculation.

this.showinformationDialog works, but when I try

var chargeRate = result.entity.get("WiChargeRate") I get 0 value

The ESQ code below:

//var building = this.get("WiBuilding");

/*

var recordId = building.value;

var esq = this.Ext.create("Terrasoft.EntitySchemaQuery", {

rootSchemaName: "WiBuildings"

});

esq.addColumn("WiChargeRate", "WiChargeRate");

esq.filters.add("IdFilter", esq.createColumnFilterWithParameter(

Terrasoft.ComparisonType.EQUAL, "Id", recordId));

esq.getEntity(recordId, function(result) {

if (!result.success) {

this.showInformationDialog("Data query error");

return;

}

this.showInformationDialog(result.entity.get("WiChargeRate"));

}, this);

*/

Hi Alex

I have resolved it. The syntax needed to be as follows:

var chargeRate = job["WiBuilding.WiChargeRate"];  //read building charge rate

Thank you for your help.

Show all comments

I'm trying to look for a way to run some javascript on every page load (edit page for a specific object schema).

From an edit page we navigate to an edit detail to create a new address. As we save the address and go back to the first edit page. At this point we want to refresh some of the fields using javascript. How can we best achieve this.

Like 0

Like

2 comments

It's not correct to reload a page any time when it appears. Please use the "messages" property instead. The reloadEntity method reloads a page.

We're aware that's not the correct way, that's why I said "something similar". 

We will look into the messages functionality, thanks!

Show all comments

Hello, 

I am wondering if anyone could help me solve this issue:

I am trying to have a calculation on the client side figure out how much time is between now (current time) and a due date set on the page.

1: I am grabbing the date from the dueDate field on the page and setting it to a variable 

2: Getting the current date and time and setting that to a variable

3 & 4: Initializing int (Number) variables via meta programming standards (not critical step)

5: set a while loop, checking if boolean/checkbox is checked off.

6: Subtracting values to find the difference with Math.abs();

7: defining the variable even further with Math.ceil();

8: Setting the value to a field on the page, with "this.set" 

This was working before I added the while() condition, am I going wrong somewhere?

I have already been trying to figure this out for 3 hours so hopefully someone can see my mistake and teach me something new, haha. 

 

Thanks, Community!

 

File attachments
Like 0

Like

3 comments

I would do something like this

define("ActivityPageV2", [], function() {
	return {
		entitySchemaName: "Activity",
		details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
		modules: /**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,
		methods: {
			onDueDateChanged: function() {
				var now = new Date();
				var dueDate = this.get("DueDate");
				var diffHrs = this.getDateDiff(now, dueDate, "hours");
				this.set("KwlString1", diffHrs.toString());
			},
			getDateDiff: function(firstDate, secondDate, identifier) {
				var diffMs = (secondDate - firstDate); // milliseconds between firstDate & secondDate
				var diffDays = Math.floor(diffMs / 1000 / 60 / 60 / 24);
				var diffHrs = Math.floor(diffMs / 1000 / 60 / 60);
				var diffMins = Math.floor(diffMs / 1000 / 60);
				switch (identifier) {
					case "milliseconds":
						return diffMs;
					case "minutes":
						return diffMins;
					case "hours":
						return diffHrs;
					case "days":
						return diffDays;
					default:
						return diffMs;
				}
			}
		},
		attributes: {
			"OnDueDateChangeAttribute": {
				dependencies: [
					{
						columns: ["DueDate"],
						methodName: "onDueDateChanged"
					}
				]
			}
		},
		rules: {},
		businessRules: /**SCHEMA_BUSINESS_RULES*/{}/**SCHEMA_BUSINESS_RULES*/,
		diff: /**SCHEMA_DIFF*/[
			{
				"operation": "insert",
				"name": "STRING8bd032e4-6e0f-4e1c-afdb-2ecf1041382b",
				"values": {
					"layout": {
						"colSpan": 12,
						"rowSpan": 1,
						"column": 0,
						"row": 9,
						"layoutName": "Header"
					},
					"bindTo": "KwlString1",
					"enabled": true
				},
				"parentName": "Header",
				"propertyName": "items",
				"index": 17
			}
		]/**SCHEMA_DIFF*/
	};
});

 

Eugene Podkovka,

Thank you for your quick response. It works well, but I was wondering how you would modify the method to: 

  1. Only set the "diffHours" once the page is initialized.
  2. Go into a while loop checking "while a checkbox is unchecked - run loop" that would set the hours/minutes/seconds remaining every second (or n time to create a "live" feel to the process).
  3. Once checkbox is checked, stop entire process and save current time. 

I added the a while loop to check if the boolean/checkbox is false (0) and it seems to be working.

As for getting this while loop to run after initialization, this is where I am having troubles, and after going through bpm'online's and the Mozilla Foundation's Documentation I turn to you, Eugene.

methods: {
	onDueDateChanged: function() {
		var now = new Date();
		var completeTask = this.get("UsrCompleteTask");
		var dueDate = this.get("DueDate");
		var diffHrs = this.getDateDiff(now, dueDate, "minutes");
        while(completeTask == 0) {
			this.set("UsrSTRING1", diffHrs.toString());
		}
	},
	getDateDiff: function(firstDate, secondDate, identifier) {
		var diffMs = (secondDate - firstDate); // milliseconds between firstDate & secondDate
			var diffDays = Math.floor(diffMs / 1000 / 60 / 60 / 24);
			var diffHrs = Math.floor(diffMs / 1000 / 60 / 60);
			var diffMins = Math.floor(diffMs / 1000 / 60);
			switch (identifier) {
				case "milliseconds":
					return diffMs;
				case "minutes":
					return diffMins;
				case "hours":
					return diffHrs;
				case "days":
					return diffDays;
				default:
					return diffMs;
			}
		}
	},

Any knowledge on how to create this would be greatly appreciated, and thanks again on your previous response! 







 

  1. Only set the "diffHours" once the page is initialized.

Please override the "onEntityInitialized" method and set the "diffHours" there.

2. Go into a while loop checking "while a checkbox is unchecked - run loop" that would set the hours/minutes/seconds remaining every second (or n time to create a "live" feel to the process).

3. Once checkbox is checked, stop entire process and save current time. 

If you need to track when people physically work on an activity then It's a very bad idea. Just let people manage how much time they spend on a task by themselves. 

Anyway, technically it would be more correct to save a current date time value when the checkbox is checked and then save it when the checkbox is unchecked. Then calculate the difference. 

 

Show all comments