Call a script Include from UI Action

hadron_collider
Tera Contributor

Hello!

 

 

Im working on a functionality that will allow to change the status of a record when a button is clicked.

 

I have an UI Action (client) so that when the button is clicked 'reason for reject' shows up and is set to mandatory:

kata90_0-1704814723056.png

 

 

I want the approver to be obliged to provide 'reject reason' to be able to change the status to 'rejected'.

 

Here is my UI action:

 

kata90_1-1704814816919.png

 

is it possible to call Script Include that will handle the logic of the record update? (changing the field value to 'rejected' and adding the 'reject reason').

 

 

Thank you in advance!

 

1 ACCEPTED SOLUTION

I corrected this in my reply above, see this

if( g_form.getValue('u_activity')== ''){   // this if was wrong
return false; //Abort submission 
}
-Anurag

View solution in original post

15 REPLIES 15

Action name uniquely identifies a ui action, this is to essentially works as server side form save button when that line executes, and we pass the action name to register what triggered the same(mimicking a server side button press). 

-Anurag

hadron_collider
Tera Contributor
function runClientCode(){
	//alert("test");
	var activityField = g_form.getControl('u_activity');
    // Make the field visible
    g_form.setDisplay('u_activity', true);
    // Make the field mandatory
    g_form.setMandatory('u_activity', true);
if( == false){
return false; //Abort submission
}


//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'expense_reject_action'); //MUST call the 'Action name' set in this UI Action
}
 

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
runBusRuleCode();

//Server-side function
function runBusRuleCode(){

current.u_reject_reason = 'Rejected';
current.exp_amount = 0;
current.update();
action.setRedirectURL(current);
gs.addInfoMessage('Record rejected successfully.');

current.update();
gs.addInfoMessage('You did it!');
action.setRedirectURL(current);
}


correction; 

// Client-Side Script
function runClientCode() {
    // Example of setting up a condition for the if statement
    if (!g_form.getValue('u_activity')) {
        return false; // Abort submission if u_activity is empty
    }

    var activityField = g_form.getControl('u_activity');
    g_form.setDisplay('u_activity', true);  // Make the field visible
    g_form.setMandatory('u_activity', true); // Make the field mandatory

    // Call the UI Action and skip the 'onclick' function
    gsftSubmit(null, g_form.getFormElement(), 'expense_reject_action');
}

// Code that runs without 'onclick'
if (typeof window === 'undefined') {
    runBusRuleCode();
}

// Server-Side Script
function runBusRuleCode() {
    current.u_reject_reason = 'Rejected';
    current.exp_amount = 0;
    current.update(); // Update the record with new values

    gs.addInfoMessage('Record rejected and updated successfully.');
    action.setRedirectURL(current);
}

So what is happening now?

What are you using the below line for

 var activityField = g_form.getControl('u_activity');
-Anurag

I removed it. it is the remaining part of the previous script version