Call a specific function of UI Action from UI Page

Nico12
Mega Sage

Hi,

 

I get a UI Page with 3 buttons. Each of them onclick call a functions of UI Action.

 

First Button call

function onOK() {
	gsftSubmit(null, g_form.getFormElement(), 'affectation); 
}

 

Second button call

function onCancel() {
	closeGlideModal(); // if cancel, close modal box
}

 

I need to call a third function from the UI Action with the third button.

How to do that ?

Is it possible to pass parameters to the gsftSubmit() function ?

 

Regards,

1 ACCEPTED SOLUTION

Ratnakar7
Mega Sage
Mega Sage

Hi @Nico12 ,

 

Yes, it is possible to call a specific function of a UI Action from a UI Page by passing a parameter to the gsftSubmit() function.

Here's an example of how you can call a third function called onThirdButton() from the UI Action with the third button:

UI Action script:

 

function onThirdButton() {
    // your code here
}

 

UI Page script:

 

function onThirdButtonClick() {
    gsftSubmit(null, g_form.getFormElement(), 'thirdButtonAction');
}

// Call onThirdButton() function of UI Action when third button is clicked
g_form.addOption('type_of_button', 'third_button', 'onThirdButtonClick()');

 

In the above example, a new function onThirdButtonClick() is defined in the UI Page script, which calls the gsftSubmit() function with the parameter 'thirdButtonAction', which is the name of the UI Action that contains the onThirdButton() function.

The g_form.addOption() method is then used to add a new option to the button dropdown list, which calls onThirdButtonClick() when the user clicks on the third button.

Regarding passing parameters to the gsftSubmit() function, you can pass an object as the first parameter to gsftSubmit(), which can contain any number of key-value pairs. For example:

 

function onOK() {
    var params = {
        'param1': 'value1',
        'param2': 'value2'
    };
    gsftSubmit(params, g_form.getFormElement(), 'affectation');
}

 

In the above example, the gsftSubmit() function is called with an object params, which contains two key-value pairs. You can access these parameters in the UI Action script using the current.getOptions() method, like this:

 

function onOK() {
    var options = current.getOptions();
    var param1 = options.param1;
    var param2 = options.param2;
    // your code here
}

 

Note that the current object in the UI Action script refers to the GlideRecord of the current record, which contains the parameters passed from the UI Page.

 

If my response helps you to resolve the issue close the question by Accepting solution and hit 👍thumb icon. From Correct answers others will get benefited in future.

 

Thanks,

Ratnakar

View solution in original post

5 REPLIES 5

Ratnakar7
Mega Sage
Mega Sage

Hi @Nico12 ,

 

Yes, it is possible to call a specific function of a UI Action from a UI Page by passing a parameter to the gsftSubmit() function.

Here's an example of how you can call a third function called onThirdButton() from the UI Action with the third button:

UI Action script:

 

function onThirdButton() {
    // your code here
}

 

UI Page script:

 

function onThirdButtonClick() {
    gsftSubmit(null, g_form.getFormElement(), 'thirdButtonAction');
}

// Call onThirdButton() function of UI Action when third button is clicked
g_form.addOption('type_of_button', 'third_button', 'onThirdButtonClick()');

 

In the above example, a new function onThirdButtonClick() is defined in the UI Page script, which calls the gsftSubmit() function with the parameter 'thirdButtonAction', which is the name of the UI Action that contains the onThirdButton() function.

The g_form.addOption() method is then used to add a new option to the button dropdown list, which calls onThirdButtonClick() when the user clicks on the third button.

Regarding passing parameters to the gsftSubmit() function, you can pass an object as the first parameter to gsftSubmit(), which can contain any number of key-value pairs. For example:

 

function onOK() {
    var params = {
        'param1': 'value1',
        'param2': 'value2'
    };
    gsftSubmit(params, g_form.getFormElement(), 'affectation');
}

 

In the above example, the gsftSubmit() function is called with an object params, which contains two key-value pairs. You can access these parameters in the UI Action script using the current.getOptions() method, like this:

 

function onOK() {
    var options = current.getOptions();
    var param1 = options.param1;
    var param2 = options.param2;
    // your code here
}

 

Note that the current object in the UI Action script refers to the GlideRecord of the current record, which contains the parameters passed from the UI Page.

 

If my response helps you to resolve the issue close the question by Accepting solution and hit 👍thumb icon. From Correct answers others will get benefited in future.

 

Thanks,

Ratnakar

Thanks Ratnakar,

 

It is exactly the informations i needed!

 

Regards,

@Nico12 Did this work for you?

Hi,

 

For what i remember, i succeed to get 3 buttons in my UI Page, and Call for each of them a specific function.