Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to set API data to our variables

    this coding is not working! actually it is a jscript program working in M3 software. i can fetch data from the API and display in the message but not able to display in the GRID! how can i set the addressLine2 variable to "data" in the function LoadData? it is giving the wrong out put! out put of addressLine 2 is now undefined data. but dialog box displays correct value from API of the software. i feel that i have to put loop also! because addressLine2 is having several data in it. please help:(

    import System;
    import System.Windows;
    import System.Windows.Controls;
    import MForms;
    import Lawson.M3.MI;
    import Mango.UI;
    import System.Windows.Media;
    import Mango.UI.Services.Lists;
    package MForms.JScript {
    class Test{
    public var addressLine2;

    var listView, oldCount;
    public function Init(element: Object, args: Object, controller : Object, debug : Object) {
    try {
    var listControl = controller.RenderEngine.ListControl;

    this.listView = controller.RenderEngine.ListViewControl;
    var columns = listView.View.Columns;
    var record = new MIRecord();
    MIWorker.Run("DRS100MI", "LstShipment", record, OnRunCompleted);
    var gvch = new GridViewColumnHeader();
    gvch.Content = "Forward Agent";
    var gvc = new GridViewColumn();
    gvc.Header = gvch;
    gvc.CellTemplateSelector = new ListCellTemplateSelector(columns.Count,listControl.Columns);
    columns.Add(gvc);
    var gvch2 = new GridViewColumnHeader();
    gvch2.Content = "Transport Equipement";
    var gvc2 = new GridViewColumn();
    gvc2.Header = gvch2;
    gvc2.CellTemplateSelector = new ListCellTemplateSelector(columns.Count,listControl.Columns);
    columns.Add(gvc2);

    var fromRow = 0;
    var toRow = listView.Items.Count - 1;
    var newNbColumns = columns.Count;
    var lastColumnIndex = columns.Count - 1;
    // increase each row's array by one additional element
    increaseRowsArray(fromRow, toRow, newNbColumns);
    // load data in the new column of each row
    loadData(fromRow, toRow, lastColumnIndex);
    // find the ScrollViewer
    var border = VisualTreeHelper.GetChild(listView, 0);
    var grid = VisualTreeHelper.GetChild(border, 0);
    var scrollViewer: ScrollViewer = VisualTreeHelper.GetChild(grid, 3);
    // attach to the OnScrollChanged event
    scrollViewer.add_ScrollChanged(OnScrollChanged);
    //scrollViewer.add_Unloaded(OnUnloaded);
    } catch (ex: Exception) {
    debug.WriteLine(ex);
    }
    }

    function OnScrollChanged(sender: Object, e: ScrollChangedEventArgs) {
    try {
    if (e.VerticalChange != 0) {
    oldCount = listView.Items.Count;
    } else {
    var fromRow = oldCount;
    var toRow = listView.Items.Count - 1;
    var newNbColumns = listView.View.Columns.Count;
    var lastColumnIndex = listView.View.Columns.Count - 1;
    increaseRowsArray(fromRow, toRow, newNbColumns);
    loadData(fromRow, toRow, lastColumnIndex);
    }
    } catch (ex: Exception) {
    MessageBox.Show(ex);
    }
    }

    /*
    Increase each row's array by one additional element.
    */
    function increaseRowsArray(fromRow, toRow, newNbColumns) {
    var rows = listView.Items;
    for (var i = fromRow; i <= toRow; i++) {
    var row = rows[i];
    var oldArray = row.Items;
    var newArray = new String[newNbColumns];
    oldArray.CopyTo(newArray, 0);
    row.Items = newArray;
    rows.RemoveAt(i);
    rows.Insert(i, row);
    }
    }



    function loadData(fromRow, toRow, columnIndex) {
    for (var i = fromRow; i <= toRow; i++) {
    addressLine2=this.addressLine2;
    var data = "" + addressLine2; // Hello CUNO
    listView.Items[i].Items[columnIndex] = data;//I want addressLine2 value to fetched here but not working
    }
    }

    public function OnRunCompleted(response: MIResponse)
    { if (!response.HasError) {
    for (var record in response.Items)
    {
    var addressLine1 = record.GetString("FWNO");

    addressLine2 = record.GetString("TRCA");// I WANT TO SET THIS VALUE to be fetched in above function loadData and in variable data

    ConfirmDialog.ShowInformationDialog(" Shipment Details", " Forward Agent- " +addressLine1 + " Transport Equipment- " + addressLine2 , null);

    }
    }
    }


    }
    }

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,302
    Thanks
    203
    Thanked 2,562 Times in 2,540 Posts
    That looks like Java to me. This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia! Ask a mod to move this thread to the right forum.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,596
    Thanks
    80
    Thanked 4,630 Times in 4,593 Posts
    That is actually JScript code, as he said.

    Microsoft, for some unholy reason, decided to support a STRANGE variant of JavaScript for server-side coding in ASP.NET.

    I doubt that there are any forums with more than a few subscribers that address this language.

    Likely the best bet is on the forums hosted by Microsoft.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •