How to visible and mandatory field once clicked on Button

Santoshi5
Giga Guru

Hi Developers,

I want to  make visible and mandatory ,explanation field once clicked on Reject button when we fill the details state changes to complete and record should be save.

Below is the UI Action &client script

client sacript:Onload()

function onLoad() {
//Type appropriate comment here, and begin script below

g_form.setVisible('u_explanation',false);

}

 

Ui Action :

find_real_file.png

find_real_file.png

 

when i clicked on button field is visible and throwing error message but not changing state as nothing is happened .. 

1 ACCEPTED SOLUTION

Great!  It looks like you marked your own response as the correct answer, which may be confusing to others that read this later.

I felt I covered that above pretty well (first) and included the script which pointed you in right direction on combination of client+server side code

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Hi,

please share updated code

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi,

please share updated script

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I tried different script its working now, hope this will help to others,

 

Ui Action script _

function rejectAnalysis(){
if (g_form.getValue('u_explanation') == '') {
// Remove any existing field message, set comments mandatory, and show a new field message
try {
g_form.hideFieldMsg('u_explanation');
} catch(e) {}
g_form.setMandatory('u_explanation', true);
g_form.showFieldMsg('u_explanation', getMessage('Please provide the explanation '), 'error');
g_form.addErrorMessage('Please enter comments in the Explnanation ');

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

// Ensure call to server side function with no browser errors
if (typeof window == 'undefined')
serverReopen();

function serverReopen() {
// Set Incident state to active, update and reload the record

current.u_quality_state = 4;
current.update();
gs.addInfoMessage(gs.getMessage("Quality Analysis Submitted."));
action.setRedirectURL(current);
}

Great!  It looks like you marked your own response as the correct answer, which may be confusing to others that read this later.

I felt I covered that above pretty well (first) and included the script which pointed you in right direction on combination of client+server side code

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader