Passing values in Webmatrix

Hi

I have created a web page using Microsoft WebMatrix.

I am having a problem passing a value to a variable.

I would like to pass to the company variable.


From my function RequestInformation() I would like to do something like company = result["AbEntry"]["Data"]["0"]["FullName"]

Is this possible or is there another way I can do this?

@using WebMatrix.Data;



@{

    Page.Title = "Sage info";

    var company = "";
    var db = Database.Open("Sage200Demo");
    var selectQueryString = "SELECT * FROM SLCustomerAccount where CustomerAccountNumber = '" + company + "'";

}




<!DOCTYPE html>
<html>
<head>
    <title>Sage info</title>
    <style>
        table, th, td {
            border: solid 1px #bbbbbb;
            border-collapse: collapse;
            padding: 2px;
        }
    </style>
</head>
<body>

  <script type="text/javascript" src="../../ClientScript/jquery/jquery.js"></script>
            <script type="text/javascript" src="../../ClientScript/MaxPage/maximizer.Events.js"></script>
    <script type="text/javascript" src="../../ClientScript/jquery/jquery.js"></script>
    <script type="text/javascript" src="../../ClientScript/MaxPage/maximizer.FollowingTabManager.js"></script>



    <script type="text/javascript">


              var tab = new maximizer.FollowingTab();
              //Subscribe to parentRecordChange event and define event handler
              tab.on("parentRecordChange", function (event) {
                  //Get the current entry key
                  var entryKey = event.data.key;

                  localStorage['SelectedKey'] = event.data.key;
                 RequestInformation()

                  //document.getElementById('myField').value = entryKey;
                  //Update the text in the tab
                  alert("The record has changed. The new record key is: " +
                    event.data.key);
                  //Dismiss the loading indicator
                  parent.$page.FollowingWindow.ontabloadend();
              });
              //Announce to the Following Tab Manager that the tab is ready
              tab.start();

              function getURLParameter(parameterName) {
                  var queryString = window.location.search.substring(1);
                  var urlParameters = queryString.split('&');
                  for (var i = 0; i < urlParameters.length; i++) {
                      var param = urlParameters[i].split('=');
                      if (param[0] == parameterName) {
                          return decodeURIComponent(param[1]);
                      }
                  }
              }

              urlMaximizerWebDataAPI = "http://" + window.location.host + "/maximizerwebdata/Data.svc/json/";

              function callMaximizerApi(baseUrl, methodName, parameters) {
                  //creating the return variable
                  var returnValue = '';
                  //creating the type of the request
                  var httpRequest = new XMLHttpRequest();
                  try {
                      //Openning the request using the provided variables
                      httpRequest.open('POST', urlMaximizerWebDataAPI + methodName,
                                       false);
                      httpRequest.onreadystatechange = function () {
                          if (httpRequest.readyState == 4 && httpRequest.status == 200) {
                              //if is everything OK with the server's answer then set the result value returnValue
                              returnValue = JSON.parse(httpRequest.responseText);
                          }
                      };

                      httpRequest.setRequestHeader('Content-Type', 'text/plain');
                      httpRequest.send(JSON.stringify(parameters));
                      return returnValue;
                  }
                  catch (err) {
                      alert(err);
                  }
              };


            function RequestInformation() {

                //separating the string
                var maxWebDataURL = getURLParameter("WebAPIURL");
                var getTokenURL = getURLParameter("GetTokenURL");
                var identityToken = getURLParameter("IdentityToken");

                //asking the token based on the identityToken
                $.ajax({
                    url: getTokenURL,
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json;charset=utf-8',
                    cache: false,
                    async: true,
                    data: JSON.stringify({ 'IdentityToken': identityToken }),
                    success: function (resultJSON) {
                        localStorage['CurrentUserKey'] = resultJSON.d;
                    },
                    error: function (resultJson) {
                    }
                });

                //after received the token lets build the request for READ the AbEntry information

                var currentUserToken = localStorage['CurrentUserKey'];
                var informationRequest = {
                    "Token": currentUserToken,
                      "AbEntry":{
                          "Scope":{
                              "Fields":{
                                  "FullName": 1,
                                  "Phone":1,
                                  "Email": 1
                              }
                          },
                          "Criteria": {
                              "SearchQuery": {
                                  "$EQ":{
                                      "Key": localStorage['SelectedKey']
                                  }

                              }
                          }

                      }
                 

                  };
                //after build the form, lets call the api and save the result in a variable
                var result = callMaximizerApi(urlMaximizerWebDataAPI, "AbEntryRead", informationRequest);

         
               
           

                alert(result["AbEntry"]["Data"]["0"]["FullName"]);

            }


        </script>

    <h1>sage info</h1>
    <table>
        <thead>
            <tr>
                <th>AccountBalance</th>

               
            </tr>
        </thead>
        <tbody>
            @foreach (var row in db.Query(selectQueryString))
            {
                <tr>
                    <td>@row.AccountBalance</td>

                </tr>
            }
        </tbody>
    </table>

       <script>
document.write(company);
</script>

</body>
</html>
Shezad AhmedAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shezad AhmedAuthor Commented:
I got it working as an ASP.Net page.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.