Solved

Passing server side values into JavaScript function

  • 20 March 2021
  • 3 replies
  • 309 views

Userlevel 1

Hi,

I need to write a JavaScript function to process an external request. For which I need to pass some values such as session, cookie, DB values, from server side into the JavaScript function.

However, I am not sure how can I pass these values from the server side after processing into javascript function. I have added a PXTextEdit control 

<px:PXTextEdit ID="UsrSessionCookie" runat="server" Size="XL" DataField="UsrSessionCookie" Visible="False" />

which I though I can use to read the values using below syntax into JavaScript but I am not able to get it if I make these PXTextEdit Visible="False".

px_alls['UsrSessionCookie'].getValue();

I have also tried below to get values but no luck-

document.getElementById("ctl00_phF_form_UsrSessionCookie");

Also, I have to make sure that server side code executes first which will get all required values and then process the JavaScript request.

Any suggestions?

Thank you

icon

Best answer by KrunalDoshi 23 March 2021, 19:22

View original

3 replies

Userlevel 7
Badge +10

Hi Krunal,

When you set Visible=false the control is not rendered at all. I had a similar requirement a long time ago and ended up leaving the control visible, but I put it inside a hidden div - something like that: <div style="display:none">

I’m pretty sure there’s a cleaner way to do that but documentation on this topic is non-existing...

Userlevel 1

Thanks Gabriel,

Putting control in hidden div will also work. I tried to hide it from graph, using

 PXUIFieldAttribute.SetVisible

and, it worked to.

@KrunalDoshi can you please help me out here. Trying to build a URL in graph extension and sending it Javascript to render it in an iframe.

This is the code, where i want to access the field vartanaKey from this GraphExtension in my javascript function 

#region Selects
public PXSelect<SOOrder> AllRecs;
#endregion

#region Event Handlers
#endregion

[PXString]
[PXUIField(DisplayName="API")]
public virtual String vartanaKey {get; set;}

public PXAction<SOOrder> VACreateOrder;
[PXButton]
[PXUIField(DisplayName = "Create Order")]
public virtual IEnumerable vaCreateOrder(PXAdapter adapter)
{
try
{
usrVAVartanaConfigGraph configGraph = PXGraph.CreateInstance<usrVAVartanaConfigGraph>();
VAVartanaConfig keyRec = configGraph.AllRecs.Select().FirstOrDefault();
vartanaKey = keyRec.UsrVAApiKey;
//throw new PXException(vartanaKey.UsrVAApiKey);
}
catch (Exception e) { throw new PXException(e.Message); }

return adapter.Get();
}



the corresponding script is added via a px:PXLiteral tag so this how it looks.

<script > var test = px_alls["vartanaKey"]; alert(test);</script>


What am i doing wrong here, can we access variables in GraphExtension somehow?

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved