Rocket Modern Experience (formerly LegaSuite)

 View Only

 How to display Engine side collected variable in page

AR VIGNESH's profile image
AR VIGNESH posted 07-17-2024 06:28
/**
* Engine Javascript
*/

import {Field} from 'mx:emulator';


const Columns = ['key','description'];
const subfile_data = Object.fromEntries(Columns.map(x => [x, []]));

class CollectJDEFunctionKeys{
        constructor(basePage) {
            this.collectfunctionKeyMethod();            
            Page.update();            
        }
                        
    async collectfunctionKeyMethod(){
        console.log("Collect Function Keys");
        const page = Page.get();  //To get page details
        console.log(`page ${page}`);
        
        var screenName =  Page.get().name; //To get page screen name
        console.log(`screenName ${screenName}`);
        
        //checking condition whether screen name is not Signon
        if(screenName != "SIGNON"){
            screen.sendKey('F24');
            await screen.waitForUpdate();
            var currentscreenNameafterF24KeyPress =Page.get().name;
            console.log(`currentscreenNameafterF24KeyPress ${currentscreenNameafterF24KeyPress}`);
            
            if(currentscreenNameafterF24KeyPress == "96012"){       
                console.log(`In 96012 screen`);
                const status = screen.fields.status;
                console.log(`status ${status}`);
                while (status.value.match(/MORE/)) {
                    console.log(`more`);
                    this.traverse();        
                    screen.sendKey('Page Down');
                    await screen.waitForUpdate()
                    status = screen.fields.status;
                    }
    
                    // Collect the last page
                    if (status.value.match(/Bottom/)){
                        console.log(`Bottom last row`);
                        this.traverse();
                        screen.sendKey('F3');
                        await screen.waitForUpdate()
                        };
                    }
  
                    console.log("Traversed Data", JSON.stringify(subfile_data));
        script.structure.Session
    }
}

     traverse(){
        // Traverse all fields and collect values
        for (const name of Columns) {
            subfile_data[name].push(...screen.fields[name].getLines());
            console.log(screen.fields[name].getLines());
        }
        }

}
const BasePage = Page.get();
var CollectFK = new CollectJDEFunctionKeys(BasePage);

Hi,

I am new to scripting in Engine side javascript.

I have created one  engine side javascript, In that I have scripted  to collect function keys and also I have stored it in json object. Now I need a solution to display it in page.

Previously We have written in VB script to collect and display it in page using global structure as Variable. Below is the structure we used,

Structure SessionStructure    
   Dim data As SessionDataStructure
End Structure

Structure SessionDataStructure
   Dim FunctionKeys as FunctionKeysStructure  
End Structure

Structure FunctionKeysStructure
   Dim key() As String
   Dim description() As String
End Structure

In Page , we call that gloabl variable to display it @&&session.data.FunctionKeys.description(0)@

below is the screenshot for your refernece.


Thanks.

Roger Van Valen's profile image
Roger Van Valen

Hi Vignesh,

To show the variables on the page, you will still need to have a global variable.

You can just keep using the structure file, and create and fill the global variable from JavaScript.

For instance, this particular set of structures can be set to the global variable 'session'  with some contents the following way:

script.global.session = new script.structure.SessionStructure({data: {FunctionKeys : { key: ['F1', 'F3', 'F5'], description: ['Help', 'Exit', 'Browse'] }}});

Of course the data I've added is just some static mocked up data, it will also be possible to just create an empty structure and fill the data dynamically in JavaScript.

Hope this helps,

Regards,

Roger van Valen.

AR VIGNESH's profile image
AR VIGNESH

Hi Roger,

Can you help me out with some dynamic data scenario?

Roger Van Valen's profile image
Roger Van Valen

Hi Vignesh,

Sure, instead of adding the text in the constructor of the creation of the object, you can also create an object of the same type without and data, and then fill the data per element.

The code would then look like this, for example:

script.global.session = new script.structure.SessionStructure();

script.global.session.data.FunctionKeys.key.push('F1');
script.global.session.data.FunctionKeys.description.push('Help');

script.global.session.data.FunctionKeys.key.push('F3');
script.global.session.data.FunctionKeys.description.push('Exit');

script.global.session.data.FunctionKeys.key.push('F5');
script.global.session.data.FunctionKeys.description.push('Browse');

And  as such the 'push'  statements can be embedded in a loop or elsewhere in the code where function keys are being collected.

Hope this helps,

Regards,

Roger.