Skip to main content
Solved

Passing server side values into JavaScript function


KrunalDoshi
Freshman II

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

Best answer by KrunalDoshi

Thanks Gabriel,

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

 PXUIFieldAttribute.SetVisible

and, it worked to.

View original
Did this topic help you find an answer to your question?

3 replies

Gabriel Michaud
Captain II
Forum|alt.badge.img+11

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...


KrunalDoshi
Freshman II
  • Author
  • Freshman II
  • 10 replies
  • Answer
  • March 23, 2021

Thanks Gabriel,

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

 PXUIFieldAttribute.SetVisible

and, it worked to.


  • Freshman I
  • 1 reply
  • April 9, 2024

@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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings