REALLY need some help with Javascript

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
Jaymer
Posts: 2523
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

REALLY need some help with Javascript

Post by Jaymer »

IN 60 SECONDS YOU CAN ADD THIS TO A GRID RENDER SCRIPT
(all you have to do is pick a BO and a specific ID, and a field name. replace my AA,1,TenantName

I'm trying to get a field value in a grid render script. There's an aware function to do just this.
And it works!, but...

per this post: https://www.awareim.com/forum/viewtopic ... 442#p51442

my code:

Code: Select all

widget.bind("dataBound", function (e) {

console.log ("Getting the value");
var theVal = new AwareApp_GetAttributeValueAction ( "AA", 1, "TenantName", null, null, function (value) {
  /** Do something with the received value */   <-- VLAD wrote this
  /** but I don't know how to reference the returned values ??? */   <--  me
  console.log( "inside value = " , theVal );
  console.log( "this inside value = " , this.theVal );
});

theVal.run ();
console.log ("outside theVal = " , theVal );
})

The Problem
I don't know how to reference the data that was returned from the server.
I can't find any examples.
Using Chrome Inspector, I can see the Network call and the valid response of the attribute value returned to the browser.
But I don't know the syntax to get to my data.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
ACDC
Posts: 1156
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Re: REALLY need some help with Javascript

Post by ACDC »

does this resolve the problem ? I would be interested to know if it does:

https://chatgpt.com/share/f404b3f3-6089 ... 5fe6e5b367
aware_support
Posts: 7560
Joined: Sun Apr 24, 2005 12:36 am
Contact:

Re: REALLY need some help with Javascript

Post by aware_support »

This action only gets a value of one particular attribute only. This value is returned as a parameter to the callback function and it is named "value" (in bold below):

var theVal = new AwareApp_GetAttributeValueAction ( "AA", 1, "TenantName", null, null, function (value) {
// do something with value, for example print it on the console:
console.log (value);
});
Aware IM Support Team
Jaymer
Posts: 2523
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: REALLY need some help with Javascript

Post by Jaymer »

aware_support wrote: Fri Jun 07, 2024 6:38 am This action only gets a value of one particular attribute only. This value is returned as a parameter to the callback function and it is named "value" (in bold below):

var theVal = new AwareApp_GetAttributeValueAction ( "NP_SessionValues", 1, "TenantName", null, null, function (value) {
// do something with value, for example print it on the console:
console.log (value);
});
Printing it on the console is the EASY, basic function.
But I need to use the value outside the scope of the callback.
Since its an async call, it complicates things.
I'm in a grid, using "widget.bind("dataBound", function (e) {. "
so I cannot get my head around this.
Preferably, I like to NOT use a callback and wait for the return from GetAttributeValueAction synchronously.

I'm already in a callback function from databound, and now I need to use another callback function GetAttributeValueAction and it doesn't make sense to me how to do this.

Here's is a simplified version of my code (which gets the value correctly, but I can't use it AFTER and OUTSIDE the callback)
RENDER SCRIPT

Code: Select all

var theVal = new AwareApp_GetAttributeValueAction ( "AA", 1, "TenantName", null, null, function (value) {
	console.log( "THIS WORKS: value = " , value );
});

widget.bind("dataBound", function (e) {
var grid = e.sender;
***** I want to set a grid.option here from a value in the callback but it is undefined *****

console.log ("Getting tenant");
theVal.run ();
console.log ("Tenant name is always undefined. Yes, I know why.  ", thename);
});
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Jaymer
Posts: 2523
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: REALLY need some help with Javascript

Post by Jaymer »

ACDC wrote: Fri Jun 07, 2024 1:51 am does this resolve the problem ? I would be interested to know if it does:

https://chatgpt.com/share/f404b3f3-6089 ... 5fe6e5b367
well, yes and no.
it gave me the syntax answer i was looking for.
what Vlad said was the same thing GPT said... my answer was in "value"
... i just wasn't seeing that and overcomplicating.
(partly due to my JS ignorance)
But my bigger issue is in my prior post.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
aware_support
Posts: 7560
Joined: Sun Apr 24, 2005 12:36 am
Contact:

Re: REALLY need some help with Javascript

Post by aware_support »

You cannot use synchronous calls to the server - they have to be asynchronous

Just do this (this is called CLOSURE in JS): (note "widget" should be available to the callback function through a closure)

var theVal = new AwareApp_GetAttributeValueAction ( "AA", 1, "TenantName", null, null, function (value) {
widget.bind("dataBound", function (e) {
var grid = e.sender;
/** Continue with what you want to do, You can use value here */
}
});

theVal.run ();
Aware IM Support Team
Jaymer
Posts: 2523
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: REALLY need some help with Javascript

Post by Jaymer »

aware_support wrote: Fri Jun 07, 2024 11:26 pm You cannot use synchronous calls to the server - they have to be asynchronous
vlad
still having trouble

i need to get TWO system fields. TWO separate calls.
Can I do this?

Code: Select all

var grid = widget; //get the grid
grid.bind("dataBound", function(e) {

	async function getHeading() {
		AwareApp_GetAttributeValueAction("SystemSettings", 1, "PP_Headings", null, null, function(value) {
			console.log("Headings = ", value);
			return value;
		})
	};

	async function getCols = new AwareApp_GetAttributeValueAction("SystemSettings", 1, "PP_NumCols", null, null, function(value) {
		console.log("NumCols = ", value);
		return value;
	})
};


var heading = await getHeading();
var numcols = await getCols(); 
});
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
aware_support
Posts: 7560
Joined: Sun Apr 24, 2005 12:36 am
Contact:

Re: REALLY need some help with Javascript

Post by aware_support »

I am not yet familiar with this new JS syntax for asynchronous functions, but it does look right. Certainly a lot easier than doing it with traditional "promises".
Aware IM Support Team
Jaymer
Posts: 2523
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: REALLY need some help with Javascript

Post by Jaymer »

Well, this doesn’t work.
at runtime in the browser console it tells me unexpected identifier found at the =

I was Trying to do it the original way you said, the only way I thought to do it was to nest the two calls.
The first one worked, but then the second one nested inside the callback Never seem to execute.
I had no way to figure out what was going on.
aware_support wrote: Mon Aug 12, 2024 3:06 am …, but it does look right.".
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
aware_support
Posts: 7560
Joined: Sun Apr 24, 2005 12:36 am
Contact:

Re: REALLY need some help with Javascript

Post by aware_support »

What do you have in the old-style code now?
Aware IM Support Team
nhofkes
Posts: 124
Joined: Mon Sep 07, 2020 6:03 am
Location: Netherlands

Re: REALLY need some help with Javascript

Post by nhofkes »

From the code it seems that you are trying to get two values from SystemSettings. Are those values dynamically changing while using the grid that the render script applies to, or is it only dynamic for separate uses of the grid but static for each actual grid? In the latter case, I found that you can incorporate the value in your render script as follows:

Code: Select all

var heading = "<SystemSettings.PP_Headings>";
var numcols = "<SystemSettings.PP_NumCols>";
(In the code, replace the single bracket (< and >) with double brackets (<< and >>) to make it an Aware tag. I couldn't put those in the text as the Wordfence plugin for this site thinks that I am doing something fishy).

This approach doesn't work when the values are changing while using the same grid. In that case, you could try nesting the function calls, i.e. put the second call within the callback function of the first call.
Niels
(V9.0 build 3272 - MariaDB - Windows)
Jaymer
Posts: 2523
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: REALLY need some help with Javascript

Post by Jaymer »

bah

i feel so stupid

var heading = '<<SystemSettings.PP_Headings>>';
var numcols = <<SystemSettings.PP_NumCols>>;

yes, i did this about 4 years ago.
can't believe I forgot.
Thx !!!
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Post Reply