Getting values from M3 panels with Jscript

Almost every M3 script needs to get values from the panel it is running on at some point and there are quite a few different ways to accomplish this. The script might need the value of a specific TextBox, the value of a cell on the selected list row or it might need to know what the name of the current program is. These are just a few examples and there are many more. This post will show how to get values from M3 panels in the most common scenarios.

Experienced script developers will probably recognize most of this but I hope you pick up something new that you didn’t know about. For new script developers this should be a good introduction of how to get the values you need in your scripts.

Note that the examples in this post do not contain any error handling to make them shorter and more readable. In production scripts you should always use try/catch, do proper null and bounds checking etc. Also note that if you get runtime errors when using the script examples your version of Smart Office is most likely too old. In this case you need to update to a newer one or stick to the functionality that was available for that particular version. If you test the script examples in other programs than the ones I used, make sure to change the fields names as well.

ScriptUtil

The ScriptUtil class has been around since the first release so this should always work regardless of the client version. The ScriptUtil class has a FindChild method that expects two parameters, the content panel and the name of the field to get. The return value of this function (if the field is found) is a WPF control that could be a TextBox, ComboBox, CheckBox or a DatePicker. To get a value you have to know the what type of control you got since the properties are different. The TextBox for example has a Text property but the CheckBox has an IsChecked property.

Unless you need to update the value of the control or change other properties on the control I would use some of the easier ways to get values described further down.

The following example shows how to get the value of the item description field (MMITDS) from the MMS001/E panel.

Script output:
MMITDS=Mango test

import System;
import System.Windows;
import System.Windows.Controls;
import MForms;

package MForms.JScript {
    class GetValueClassic {
        public function Init(element : Object, args : Object, controller : Object, debug : Object) {
            var content : Object = controller.RenderEngine.Content;
            var fieldName = "MMITDS";
            var textBox = ScriptUtil.FindChild(content, fieldName);
            if (textBox != null) {
                var value = textBox.Text;
                debug.WriteLine(fieldName + "=" + value);
            } else {
                debug.WriteLine("Could not find a field named " + fieldName + " on the current panel");
            }
        }
    }
}

ScriptUtil and MFormsUtil

The MFormsUtil class has a method called GetControlValue and this method knows how to get the value from the controls that may appear on a M3 panel. In this case you don’t have to worry about the type of control you got from ScriptUtil.FindChild method, you just pass the result to MFormsUtil.GetControlValue to get the actual value.

The following example shows how to get three values from three different types of controls (TextBox, ComboBox and CheckBox) from the MMS001/E panel.

Script output:
MMITDS=Mango test
MMSTAT=20
MMECMA=1

import System;
import System.Windows;
import System.Windows.Controls;
import MForms;

package MForms.JScript {
    class GetValueUtil {
        var content;
        var debug;
        public function Init(element : Object, args : Object, controller : Object, debug : Object) {
            this.content = controller.RenderEngine.Content;
            this.debug = debug;
            var fieldName;
            var value;

            // TextBox example
            fieldName = "MMITDS";
            value = GetValue(fieldName);
            debug.WriteLine(fieldName + "=" + value);

            // ComboBox example
            fieldName = "MMSTAT";
            value = GetValue(fieldName);
            debug.WriteLine(fieldName + "=" + value);

            // CheckBox example
            fieldName = "MMECMA";
            value = GetValue(fieldName);
            debug.WriteLine(fieldName + "=" + value);
        }

        private function GetValue(fieldName) {
            var element = ScriptUtil.FindChild(content, fieldName);
            if (element != null) {
                var value = MFormsUtil.GetControlValue(element);
                return value;
            }
            debug.WriteLine("Could not find a field named " + fieldName + " on the current panel");
            return null;
        }
    }
}

PanelState

The PanelState is a property on the controller instance that is passed to the Init method of the script. If the PanelState property is available in the client version you are targeting it is the easiest way to get values from the panel.

The PanelState has a read-only indexer that accept the name of a field. An indexer in .NET uses the array indexing syntax with angle brackets but the value between the brackets can be of any type, in this case it’s a string. The line of code below shows how this could be used directly in the Init method to get a field value, in this case the item description on the MMS001/E panel.

var itemDescription = controller.PanelState[“MMITDS”];

Note that the indexer is read-only so there is no way to set a value using the indexer. To set a value you need to get the control and set the correct property.

The following example shows how to get three values from three different types of controls (TextBox, ComboBox and CheckBox) from the MMS001/E panel. This example in basically the same as the previous one but using the PanelState indexer instead of the ScriptUtil/MFormsUtil classes.

Script output:
MMITDS=Mango test
MMSTAT=20
MMECMA=1

import System;
import System.Windows;
import System.Windows.Controls;
import MForms;

package MForms.JScript {
    class GetValuePanelState {
        public function Init(element : Object, args : Object, controller : Object, debug : Object) {
            var panelState = controller.PanelState;
            var fieldName;
            var value;

            // TextBox example
            fieldName = "MMITDS";
            value = panelState[fieldName];
            debug.WriteLine(fieldName + "=" + value);

            // ComboBox example
            fieldName = "MMSTAT";
            value = panelState[fieldName];
            debug.WriteLine(fieldName + "=" + value);

            // CheckBox example
            fieldName = "MMECMA";
            value = panelState[fieldName];
            debug.WriteLine(fieldName + "=" + value);
        }
    }
}

In addition to the indexer the PanelState exposes a couple of other interesting properties. You can get the name of the program as well as the name, letter, header and description of the panel. If a message has been displayed by the BE program you can get the message text and the message ID. The date format of the current program is also available.

The SortingOrder and View properties will return values when the script is running on a list panel. These two properties can also be set. When the sorting order and view are displayed in a ComboBox and either of these are set there will be an automatic server request so you need to keep this in mind when setting sorting order or view. In some programs the sorting order and view are displayed as TextBoxes and in in these cases you need to call the PressKey method manually since there is no automatic request when TextBoxes are used. Sorting order and view was previously called Inquiry type and Panel version.

The following example is a script that outputs the PanelState properties on two different panels, MMS001/B and MMS001/E. On the E-panel I typed an incorrect value to get an example of the message properties.

Script output (MMS001/B):
PanelState properties
JobId : eefde665b2004894be68413db4896d7b
ProgramName : MMS001
PanelName : MMA001BC
PanelHeader : MMS001/B
PanelDescription : Item. Open
PanelLetter : B
SortingOrder : 1
View :
Message :
MessageId :
DateFormat : yyMMdd

Script output (MMS001/E):
PanelState properties
JobId : eefde665b2004894be68413db4896d7b
ProgramName : MMS001
PanelName : MMA001E0
PanelHeader : MMS001/E
PanelDescription : Item. Open
PanelLetter : E
SortingOrder :
View :
Message : Responsible 98765 does not exist
MessageId : WRE0103
DateFormat : yyMMdd

import System;
import System.Windows;
import System.Windows.Controls;
import MForms;

package MForms.JScript {
    class PanelStateProperties {
        private var debug;
        public function Init(element : Object, args : Object, controller : Object, debug : Object) {
            this.debug = debug;
            debug.WriteLine("PanelState properties");
            WritePanelState(controller.PanelState);
        }

        private function WritePanelState(panelState) {
            WriteProperty("JobId ", panelState.JobId);
            WriteProperty("ProgramName ", panelState.ProgramName);
            WriteProperty("PanelName ", panelState.PanelName);
            WriteProperty("PanelHeader ", panelState.PanelHeader);
            WriteProperty("PanelDescription ", panelState.PanelDescription);
            WriteProperty("PanelLetter ", panelState.PanelLetter);
            WriteProperty("SortingOrder ", panelState.SortingOrder);
            WriteProperty("View ", panelState.View);
            WriteProperty("Message ", panelState.Message);
            WriteProperty("MessageId ", panelState.MessageId);
            WriteProperty("DateFormat ", panelState.DateFormat);
        }

        private function WriteProperty(name, value) {
            debug.Write(name + ": ");
            if (value != null) {
                debug.Write(value);
            }
            debug.WriteLine(" ");
        }
    }
}

List row values

A common scenario is to get the value for a column of a selected list row. This is very easy when using the GetColumnValue of the ListControl class. Just pass the name of the column and you will get back the value for that column on the currently selected list row. You can also get the value for any list row by first getting a reference to that list row and passing that as the second parameter to the GetColumnValue method.

The following example for the MMS001/B panel first shows how to get a column value for the selected list row and then how to get a value from the fifth list row. Note that the example assumes that there are at least five rows in the list.

Script output:
Column value for selected list row
S1ITNO=MANGO

Column value for any list row
S1ITNO=MANGO_STATUS

import System;
import System.Windows;
import System.Windows.Controls;
import MForms;

package MForms.JScript {
    class GetValueList {
        public function Init(element : Object, args : Object, controller : Object, debug : Object) {
            var listControl = controller.RenderEngine.ListControl;
            var fieldName;
            var value;

            debug.WriteLine("Column value for selected list row");
            fieldName = "S1ITNO";
            value = listControl.GetColumnValue(fieldName);
            debug.WriteLine(fieldName + "=" + value);

            debug.WriteLine("");
            debug.WriteLine("Column value for any list row");
            var listRow = listControl.ListView.Items[4];
            value = listControl.GetColumnValue(fieldName, listRow);
            debug.WriteLine(fieldName + "=" + value);
        }
    }
}

Position field values

The position fields in the list are included when using the PanelState indexer but you can also use the GetPositionFieldValue method on the ListControl class. There is also a PositionField property on the ListControl class that is a list of all the position fields.

The following example for the MMS001/B panel shows how to get a value using the GetPositionFieldValue and how to iterate all position fields in the list.

Script output:
Specific position field
W1ITNO=MANGO

All position fields
W1ITNO=MANGO
W1ITTY=01

import System;
import System.Windows;
import System.Windows.Controls;
import MForms;

package MForms.JScript {
    class GetValuePositionField {
        public function Init(element : Object, args : Object, controller : Object, debug : Object) {
            var content : Object = controller.RenderEngine.Content;

            var listControl = controller.RenderEngine.ListControl;

            debug.WriteLine("Specific position field");
            var fieldName = "W1ITNO";
            var value = listControl.GetPositionFieldValue(fieldName);
            debug.WriteLine(fieldName + "=" + value);

            debug.WriteLine("");
            debug.WriteLine("All position fields");
            for (var field in listControl.PositionFields) {
                debug.WriteLine(field.Name + "=" + field.Text);
            }
        }
    }
}

DatePicker

When getting the value from a DatePicker on the panel you need to consider what you want to use the value for. The PanelState indexer will return a string with the date in the current M3 date format. The Value property on the DatePicker control will return a .NET DateTime struct. You can always convert a date string to a DateTime and vice versa but you need to know which one you want to use.

The following example for the OIS100/A panel first shows how to get the value from DatePicker control, then how to get the value using the PanelState indexer and finally how to convert the string date to a DateTime.

The M3Format class used in this example also has two other methods for converting strings to typed values and these are ToDouble and ToBool that accepts a single string parameter and returns a type value using the current M3 decimal format for double and “0”/”1″ for bool.

Script output:
DatePicker using the Value property
WARLDZ=2013-12-24

DatePicker using the PanelState indexer
WARLDZ=131224

Value converted using the date format of the current panel
WARLDZ=2013-12-24

import System;
import System.Windows;
import System.Windows.Controls;
import MForms;

package MForms.JScript {
    class GetValueDatePicker {
        public function Init(element : Object, args : Object, controller : Object, debug : Object) {
            var content = controller.RenderEngine.Content;
            var panelState = controller.PanelState;
            var fieldName;
            var value;

            fieldName = "WARLDZ";

            debug.WriteLine("DatePicker using the Value property");
            var datePicker = ScriptUtil.FindChild(content, fieldName);
            value = datePicker.Value;
            debug.WriteLine(fieldName + "=" + value.ToShortDateString());

            debug.WriteLine("");
            debug.WriteLine("DatePicker using the PanelState indexer");
            value = panelState[fieldName];
            debug.WriteLine(fieldName + "=" + value);

            debug.WriteLine("");
            debug.WriteLine("Value converted using the date format of the current panel");
            var dateTime = MForms.Mashup.M3Format.ToDate(value, panelState.DateFormat);
            debug.WriteLine(fieldName + "=" + dateTime.ToShortDateString());
        }
    }
}

How to find the name of a field

All the examples in this post requires that you know the name of the field that you want to get the value for. The easiest way to get the field name if to use the field help by pressing F1 when the control has keyboard focus or by using the context menu and selecting Field help. The value in parenthesis in the lower right corner of the field help window is the name of the field.

Sometimes there is no field help or there is no way to display it. In these cases you have to use other means to find the field name. One example is to use the Condition styles wizard found under Tools -> Personalization. The target field ComboBox will show the names of the fields.

Another options is to check the response XML where you are guaranteed to see all fields. There is a hidden way to show the response XML for a panel. Hold down the shift key on the keyboard and then right-click on some empty space on the panel (not on a control, above the list on list panels). The context menu that is displayed should contain a Debug menu and under that you will find the option Show Response XML. This will open the response XML in an Internet Explorer browser. If you can’t see the Debug menu it might be because you right-clicked without holding down the shift key, in this case refresh the panel and try again. If there still is no Debug menu the client might be too old.

Context menu
M3GPV_DebugMenu

Response XML
M3GPV_ResponseXml

64 thoughts on “Getting values from M3 panels with Jscript

  1. Jonas

    Great information and very helpful!!

    One thought, when looking at the response XML.
    I found a thing that’s been bugging me for some time, how to read or set the state of a field.
    To set the state of the field to read-only i’ve historically used the .IsEnabled = false setting for the field and reduced opacity to 0.7 to fit the style of read only fields.

    It looks to me, when looking at the XML, that acc=”WE” or WD sets the state of read/write access for a field(?)

    To my question:
    When entering a panel i wish to verify if the panel is in view (opt. 5) or change (opt. 2).

    What’s the best way to figure out if a field is WE (Write Enabled) or WD (Write Disabled) – how can i get those values?
    Are there any other best practices for this in SmartOffice?

    1. karinpb

      Hi,
      The way to check is a field is enabled or not is to check the style of the TextBox. If the style is styleTextBoxDisabled the field is disabled. All disabled TextBoxes have this style.
      var isEnabled = true;
      If (yourTextBox.Style == Mango.UI.Core.StyleManager.StyleTextBoxDisabled){
      isEnabled=false;
      }
      As for the the view (opt 5) or change (opt 2) I don’t think we have that information on the client.
      Sorry for the late reply.

      1. Jonas

        Ok.. that does help a lot!

        I found another property that i could check to determine if the field is editable.
        To be able to complete the current script, i check one field that i know is editable if the user enters with opt 2, if it has the property AllowDrop.
        If it’s true, it means that it’s editable and the user has entered the panel with change rights.
        If it doesn’t allow drop i just return and it’s no point to go further in the script.

        Thanks for your clarification of the the style, i will use it to clean up my existing generic script for disabling fields.

      2. Fanny

        Hi,
        Excellent blog!
        You describe how to check if a field is enabled or not. What is the advised way to set it to read-only? Is it done as Jonas describes above or is there a better way?
        Jonas writes: “To set the state of the field to read-only i’ve historically used the .IsEnabled = false setting for the field and reduced opacity to 0.7 to fit the style of read only fields.”

        I would like to make the “facility” field in OIS300/B read-only for certain roles, so that they cannot change facility.

      3. karinpb

        I I would not do it like Jonas describes. Instead I would use the Mango.UI.StyleManager.StyleTextBoxDisabled and set that style on the TextBox, or if you have another control check the StyleManager in the API documentation or use DotPeek and have a look in Mango.UI.

        textBox.Style = StyleManager.StyleTextBoxDisabled
      4. Fanny

        Thanks, this works. I also set the text of the textbox to 750, so that facility 750 is defaulted and cannot be changed. I added PressKey F5 to reload the listview, because otherwise the listview still contains orders of the other facility. This works when I run the script from the ScriptTool, but not when I added the script to Personalizations. It seems that F5 is not pressed. Is this the right way to reload the listview?

        import System;
        import System.Windows;
        import System.Windows.Controls;
        import MForms;
        import Mango.UI.Core;

        package MForms.JScript {
        class OIS300Facility750ReadOnly {
        public function Init(element: Object, args: Object, controller : Object, debug : Object) {
        debug.WriteLine(“Script Initializing.”);
        if(element != null) {
        debug.WriteLine(“Connected element: ” + element.Name);
        }

        var content : Object = controller.RenderEngine.Content;
        var renderEngine = controller.RenderEngine;
        var fieldName = “WWFACI”;
        var textBox = ScriptUtil.FindChild(content, fieldName);

        try {
        if (textBox != null) {
        var value = textBox.Text;
        debug.WriteLine(fieldName + “=” + value);
        textBox.Text = “750”
        textBox.Style = StyleManager.StyleTextBoxDisabled;
        controller.PressKey(“F5”);
        }
        } catch(ex) {
        }
        }
        }

      5. Jonas

        The problem i have seen with only setting a field to StyleManager.StyleTextBoxDisabled is that for any browse fields you can still select the field and press F4 to browse for value, select a new value and update the field. The style can be combined with IsEnabled to disable this possibility, with the downside that any text in the field can not be selected and copied for example.

        Maybe there is another function that can control whether the user can press F4 or not since the small arrow for clicking browse is removed by the style? 🙂

      6. Fanny

        Thanks, Jonas. You are right, I could still use F4 and select another value. The textbox itself did not display the newly selected value, but the results in the listview were updated for the new value. I disabled the field and now the F4 issue is solved.

        The only problem I have left now, is that the first time a user opens OIS300 with the script connected to it, the facility textbox shows 750, but the listview displays the lines for facilty 1. The 2nd time OIS300 remembers that facility 750 was last used and the listview shows the correct lines. Is there a way to refresh the listview or do you have to rebuild it completely in the code? My code so far:
        import System;
        import System.Windows;
        import System.Windows.Controls;
        import System.Windows.Threading;
        import MForms;
        import Mango.UI.Core;

        package MForms.JScript {
        class OIS300Facility750ReadOnly {

        var debug;
        var textBox;
        var controller;

        public function Init(element: Object, args: Object, controller : Object, debug : Object) {

        this.debug = debug;
        this. controller = controller;
        var content : Object = controller.RenderEngine.Content;
        var fieldName = “WWFACI”;
        this.textBox = ScriptUtil.FindChild(content, fieldName);

        var action : Action = SetFacility;
        Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, action);

        }

        private function SetFacility() {

        if (textBox != null) {

        var value = textBox.Text;

        textBox.Text = “750”
        textBox.Style = StyleManager.StyleTextBoxDisabled;
        textBox.isEnabled = false;

        }
        }
        }
        }

      7. Jonas

        I think you can just add an enter after changing value and disabling the field.
        controller.PressKey(“ENTER”);

      8. Jonas

        ..on second thought you might also want to add to check the current value of the field in order to not trigger any strange loops, since the form is reloaded after enter is pressed and possibly the script is triggered to run again.

        Something Like:
        if (textBox != null) {

        var value = textBox.Text;
        textBox.Style = StyleManager.StyleTextBoxDisabled;
        textBox.isEnabled = false;

        if (value != “750”)
        textBox.Text = “750”;
        controller.PressKey(“ENTER”);
        }
        }

  2. Jsenser

    Hi,
    Thanks for all this information !
    I need to add a question : is it possible to get the context into a script ?
    In example, i’m on OIS100/A panel and i need to know if previous panel is QPS115 or OIS300. Is it possible to test it on a scipt attached to OIS100 ?

  3. Jonas

    This proved to be a very useful post.. but i’m back with a thing that’s bugging me.
    In program OIS101/H* (go through OIS101, press F18 to get there)

    When trying to set a value to PanelState.SortingOrder i face the problem described in your post:

    “”In some programs the sorting order and view are displayed as TextBoxes and in in these cases you need to call the PressKey method manually since there is no automatic request when TextBoxes are used””

    When trying this, it works superb in Script Tool and the panel refreshes fine, but as soon as the script is run from server it only changes the value in sorting order but the panel itself is not refeshed from H1 to H8 in this example.

    I’ve tried to add PressKey(“ENTER”) after setting the sorting order, but it seems to be ignored – possibly because when changing the SortingOrder it halts the script(?).

    In this program i can do a dirty workaround to check if panel is 1 or 2 and use PressKey(“F10”) to go to next sorting order – finally ending up on #8.

    Do you have some tricks up your sleeve that could help out to actually call PressKey successfully when changing SortingOrder?

    1. Jonas

      Sorry, sometimes it helps to just ask..
      I found the solution and reason.

      As in some other programs it executes the server script before the panel is fully loaded.
      Listening on the ListViews event OnGotFocus before setting SortingOrder, works when the script is executed on server. (without having to send PressKey)


      var lvListView : ListView = controller.RenderEngine.ListControl.ListView;
      lvListView.add_GotFocus(OnGotFocus);

      function OnGotFocus(sender : Object, e : RoutedEventArgs) {
      try
      {
      controller.PanelState.SortingOrder = 8;
      }
      catch(ex)
      {
      debug.WriteLine(ex);
      }
      }

      1. norpe Post author

        One issue with that solution is that the BE program might set keyboard focus in the list header and that case your script code won’t run until the user sets focus to the list (and that could be very confusing). You could use the Dispatcher and delay your script execution (using DispatcherPrioriry.Background for example) so that the list is completely initialized if that is the issue. Just make sure to check that the script is still valid when the function is invoked by the Dispatcher (that the Requested event has not fired for example).

  4. Silvia

    Hi,

    Great information! I’m new to scripts and got a question how to fill M3 fields using arguments in the same panel.
    I have an example: In OIS165 the user has to fill TECH, WHSL, WHLO always with the same value. We want to make it faster for the user and create a shortcut which automatically fills those fields with specific values. The values are the same for group of people but different per role. That’s why I want to create a script using arguments, I don’t want to hard-code the values in the script. Can anyone please help how it is possible?
    Thank you!

    1. norpe Post author

      Scripts in MForms are personalizations and different personalizations can be deployed to different roles / users. You can have one generic script and different script arguments for different roles / users.

      1. Silvia

        Hi,

        Thanks for the quick answer. I’m familiar with personalization and using scripts. I’m new to writing scripts and I’d need a script example for the above case.
        Thank you!

      2. Silvia

        I try to formulate my question differently.
        I understand how to get a field value from a program, e.g.:

        var fieldName = “W1ITNO”;
        var value = listControl.GetPositionFieldValue(fieldName);

        But how can I write a field in M3 using a script with arguments?

        Thanks!

    1. karinpb

      Hi Grigoryev,
      You need to be more specific. If this is for calling an MI program then there is only one common setting in Mango.Core settings that is used for WS connections. Unless the method used can take the timeout as a parameter. I think that MIParameters that can be set when you use MIWorker can set both the ConnectTimeout and the ReceiveTimeout, which will then be valid for that call only. Please clearify what timeout you are refering to.

  5. Priyantha

    I am developing script for readonly editable column in M3. but in m3 editableCell don’t have property . anyone have idea , how can I do it . program name is m3 supplier invoice and column name is Inv Qty . please help me.

    1. karinpb

      Hi,
      I missed the question here. If you still have issues check in a tool like Snoop UI. Always refer to columns with the field name (combined with the header is OK). I’m not sure I know a supplier with data in our system.

      1. Priyantha

        InstanceController con = (InstanceController)controller;
        Object content = con.RenderEngine.Content;

        // TODO Add your code here
        MForms.ListControl listControl = con.RenderEngine.ListControl;
        System.Windows.Controls.ListView listView = con.RenderEngine.ListViewControl;

        ItemCollection rows = null;

        rows = listView.Items;

        foreach (Mango.UI.Services.Lists.ListRow item in rows)
        {
        int column1 = listControl.GetColumnIndexByName(“IVQA”);
        EditableCell cell = item[column1] as EditableCell;

        }

        in EditableCell don’t have readonly property . please help me .

  6. Malsab

    Hi !
    First at all, great job. This help a lot.
    But I have an another problem. I want to get the panel’s fieldnames or columns.. I tried with “listView.View.Columns” but it’s no successful. Is it possible ?

    1. norpe Post author

      The MForms ListControl class has two properties for getting the names of the list columns. The Columns property returns a list with the short 4 character list column names. The ColumnNames property returns a list of the full six character column names. You can get a reference to the ListControl from controller.PanelState.ListControl. Note that the ListControl property will be null if there is no list on the current panel.

      1. Malsab

        Perfect, it’s work fine ! Just on another question : did you know if we can use AJAX in jscript ?

      2. karinpb

        Hi Malsab,
        You can’t use “AJAX” since that is a javascript technology but I guess you mean make web requests. You can do we requests as long as you make them on a background thread. Never call a server on the UI thread. Check for example system.net.webrequest. The link is for .Net 4.0.

  7. Urban Görander

    Hi
    How do code in M3 Jscript look like if you want to run a script when you clicked on a buttom in for example OIS100/V and then want to start an link //:url with input ordernr and email adress
    The code i am interested on is how the script recognize that the user click on the specific buttom

  8. Daniel

    Little off topic..
    I want to add an additional datepicker using jscript. How do populate one that looks like all other datepickers? simply creating one with var datePicker = new Mango.UI.Controls.DatePicker(); and place it gives you a datepicker that doesn’t look like the normal ones.

    /Daniel

      1. norpe Post author

        You need to import Mango.UI.Controls and also qualify the name otherwise the standard .NET DatePicker will be used.

        The first example below is a date picker where the value can only be selected from the calendar. The second example allows editing the date with a specific format.


        import Mango.UI.Controls;

        var datePicker = new Mango.UI.Controls.DatePicker();
        datePicker.Value = DateTime.Now;


        import Mango.UI.Controls;

        var datePicker = new Mango.UI.Controls.DatePicker();
        datePicker.DateFormat = "yyyy-MM-dd";
        datePicker.Value = DateTime.Now;
        datePicker.CanEdit = true;

      2. Daniel

        Thank you for your input. I also had to play around with the width a little bit but now they are quite similar.

  9. Joe Walker

    Hi All – is anyone aware of any way which you can change the panel sequence in a B panel with a script? This needs to be the equivalent of doing Direct Change and altering the panel sequence rather than going through the F13 settings. The reason for this is I just want to open up the lines in PMS100 in display mode – so I would change the panel sequence to 1 and then do basic option Display with a button. But I do not want to change the users default panel sequence so when they reopened the function it would revert back to their standard one.

    Thanks,
    Joe

    1. karinpb

      Hi,
      It is possible but I don’t have an example. We don’t recommend you to implement a script like this since it would change the user’s settings. The script would take a few hours to create.

  10. Harryliu

    Hi All – when I use MFormsAutomation ->listoption=11,how to set value for listview EditableCell.

    data[‘1’] = [“crc”, “1” ,”010104″ ,”2″ ,”cc2b” ,”129101002″ ,”CH14″ ,”5″ ,”0″ ,”0″];
    for( var x in data)
    var auto = new MFormsAutomation();
    auto.AddStep(ActionType.Run, ‘OIS811’);
    auto.AddStep(ActionType.Key, ‘ENTER’);
    auto.AddField(‘WWDISY’, data[x][0]);
    auto.AddField(‘WWDIPO’, data[x][1]);
    auto.AddField(‘WWFVDT’, data[x][2]);
    auto.AddField(‘WWPREX’, data[x][3]);
    auto.AddStep(ActionType.Key, ‘ENTER’);
    auto.AddField(‘WWOBV1’, data[x][4]);
    auto.AddField(‘WWOBV2’, data[x][5]);
    auto.AddStep(ActionType.Key, ‘ENTER’);
    //open OIS812 PANEL
    auto.AddStep(ActionType.ListOption, ’11’);
    auto.AddStep(ActionType.Key,’ENTER’);
    auto.AddField(‘W1CMPN’,data[x][6]);
    auto.AddStep(ActionType.ListOption, “-1”);
    ————
    auto.AddField(‘DISP’, 10);
    or
    var listControl = controller.RenderEngine.ListControl;
    var listView = listControl.ListView;
    listView.Items[0].Items[‘DISP’][1].Text = 10;
    ————–

    var uri = auto.ToUri();
    DashboardTaskService.Manager.LaunchTask(new Task(uri));

    }

    1. norpe Post author

      The field names for the editable list cells have the format RnCn where n is a 1-based row or column index. The first cell on the first row would have the name R1C1, the second cell on the first row would have the name R1C2 and so on.

      Just be careful when converting between the 0-based indexes in the .NET collections and the 1-based indexes for the cell names to avoid off-by-one bugs.

      You can check the response XML to see the cell names for the LC elements using either Fiddler or the Debug > Show Response XML menu item (Shift+Right click in the list header (not on a field)).

      1. Harryliu

        I want to import excel data by using button . After listoption(11) operation it open new programmer, If the field bind with textbox , I can still use MFormsAutomation function to finish it ,for example: auto.AddField(‘DISP’, 10). But it bind with listview, how can I to set value for the field DISP .

      2. Harryliu

        [[code]
        XML FILE:

        Disc

        0.00

        [/code]]
        how to specify the EditableCell value by using MForms Automation functions

      3. Harryliu

        LIST:NAME=”OIA812ES”
        LView name = “0”
        LCol name = WSDISP
        LR name = “R1”
        LC name = “R1C2”

  11. cs

    Hi there, Just had a quick question that I think there’s a pretty easy answer to, but it has got me a little bit stumped probably due to my inexperience with JScripts. I was looking to retrieve some information from a listview in M3 (STS201), I wanted to pull back the information for all the listrows and used the List Values example above as a guide, I can retrieve the information for selected rows and also specific rows:

    var listControl = controller.RenderEngine.ListControl;
    var fieldName;
    var lot;
    fieldName = “WSSERI”;
    var listRow = listControl.ListView.Items[2];
    lot = listControl.GetColumnValue(fieldName, listRow);
    debug.WriteLine(fieldName + “=” + lot);

    I wondered how I would go about extending the search to all the rows in the list views, I’ve figured out that I think I need to use a For loop to loop through all the rows but I just don’t seem to be able to get it working just right, I either get an error or only a single value returned.

    Thanks

    1. norpe Post author

      See the code example below. Note that the ListView items will only contain the rows that have currently been loaded on the client (usually 33 rows for the first batch in a regular M3 list panel).

      import System;
      import System.Windows;
      import System.Windows.Controls;
      import MForms;
      
      package MForms.JScript {
          class GetRowValues {
              public function Init(element : Object, args : Object, controller : Object, debug : Object) {
                  var listControl = controller.RenderEngine.ListControl;
                  var rows = listControl.ListView.Items;
                  var fieldName = "MMITNO";
      
                  for (var i = 0; i < rows.Count; i++) {
                      var row = rows[i];
                      var value = listControl.GetColumnValue(fieldName, row);
                      debug.WriteLine(fieldName + "=" + value);
                  }
              }
          }
      }
      
  12. Ester

    Hi,

    I want to read the description of FAM function in APS100/E, that is WTFNCN field. I tried with these two instructions
    var FTCN1 = controller.PanelState[“CTTX40”];
    var FTCN2 = ScriptUtil.FindChild(content, “WTFNCN”);

    but I did not get any result, any idea ? Should I use a different instruction as it is a CSYTAB field, I mean is not an open field?

    Thanks

  13. Farhat

    Hi,

    I need a help?
    I require to add some new fields(which is not related to M3 ) in OIS100H panel, an get those fields value in different panel in OIS102/B.
    How i can persist values in user session or controller?

    I have read SDK document but did not get any idea as they have not thoroughly describe life cycle.

    I have couple of idea but i don’t think so it would have recommend or good practice to do.

    RenderEngine only show current panels content, what i should do to access other panel content and user control content.

    Please help
    It is show stopper for me.

    Appreciated and thanks in advance.

  14. Kurt Jensen

    Hi.
    I have a challenge where I could need a little help. In PPS170/B (Planned purchase orders) I am making a script that checks something about the item number and if certain criteria matches there is a message displayed and the operation is cancelled the first time but to allow the user to make the operation anyway I remove the script from the controller.requesting event until the next time (I hope you understand what I mean). The problem is that if the user moves to another item number then the script are not run and the user will not be notified if that item also matches the criteria.
    The question is that instead of disabling the script, how can I check if it is the same item/row that it was the last time the user tried to open a line and then allow opening it and if not then perform the check?
    I am using c# to make the scripts (compiled dll)

    Hope to get an answer

  15. Farhat

    Hi,
    we can use SessionCache for scripts that can be used to cache items in the MForms session.

  16. Pingback: Developing H5 Client scripts – M3 ideas

  17. Yvon

    Hi,

    I am trying to know if it is possible to initialize in script a standard combobox of a viewdef. I tried .selectedIndex but it does not work.

    thank you for your reply

    best regards

  18. Bhumika Lekurwale

    Hi, I need some to set some value to TextBox of a field available on E panel.
    Can someone guide me.

    Regards,
    Bhumi

  19. Bhumika Lekurwale

    Can anyone suggest…
    How to make the response returned by MI available globally, so that it will be accessible in other methods!

    Thanks

    1. Kurt Jensen

      How about putting the information you need in some SessionCache variables like I just learned earlier in this thread?

  20. Anthesis

    In PPS220 you can confirm an order line to set a confirmed price and delivery date. I’d like to set the confirmed price as read only or remove it from the array. Is this possible?

    I’ve got a similar script running in PPS300 where it pulls the item price i.e. copies the array and adds columns on containing the price. We’ve also got scripts in play where we make a standard field read only but making a field in an array (in a column) read only is proving difficult.

  21. MANU SHARMA

    I am using this script clearing the default CSYSTR values from the start screens.

    import System;
    import System.Windows;
    import System.Windows.Controls;
    import MForms;
    package MForms.JScript {
    class PPS300A {
    public function Init(element : Object, args : Object, controller : Object, debug : Object) {
    var content : Object = controller.RenderEngine.Content;
    ScriptUtil.FindChild(content, ‘WWTRDT’).Clear();

    }
    }
    }

    but somehow this is not working on the datepicker fields

    any advise if greatly appreciated.

Comments are closed.