can someone help me to userstand UI action how its working client and server side together with example ..?

s_kumar
Mega Contributor

Request

1 ACCEPTED SOLUTION

zica
Giga Guru

Okay perfect,



Here is a screenshot that shows the parameters of the UI action, Please do the same


Do not forget to put the action name, check client to true, and put the function name on Onclick()


Capture d



HEre is the script :



function reopenIncidentTest(){


     


      if (g_form.getValue('comments') == '') {


              //Remove any existing field message, set comments mandatory, and show a new field message


              try {


                    g_form.hideFieldMsg('comments');


              } catch(e) {}


                    g_form.setMandatory('comments', true);


                    g_form.showFieldMsg('comments','Reason is required when reopening an incident','error');


                      return false;   //Abort submission


        }


      //Call the UI Action and skip the 'onclick' function


      gsftSubmit(null, g_form.getFormElement(), 'incident_reopen_test'); //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')


      serverReject();



function serverReject(){


      current.state = 2;


      current.update();


}


View solution in original post

31 REPLIES 31

This does not seem to be work for Change Form. Below is the script i have mentioned in Reject UI Action to ensure that the rejection comments are mandatory before rejecting the Change Ticket via "Right Click" option on the Approver related list in the Change Form. Unfortunately, I am able to see the comments mandatory but Approver record is not getting Rejected.

 

function rejectRequest()

{
if (g_form.getValue('comments') == '')

{
//Remove any existing field message, set comments mandatory, and show a new field message

try {
g_form.hideFieldMsg('comments');
} catch(e) {}

g_form.showFieldMsg('comments','Please provide comments for rejection.','error');

return false; //Abort submission

}

//Call the UI Action and skip the 'onclick' function

gsftSubmit(null, g_form.getFormElement(),'Rejection'); //MUST call the 'Action name' set in this UI Action

}

if (typeof window == 'undefined')

serverReject();

function serverReject()

{

current.state= 'rejected';

current.update();

}

Balu5
Tera Contributor

Hi All
i have ui action script for refer back knowledge article when ever approver refer back a KBA if is reflecting other KBA other KB approvals also set as No Longer requested.

Below is the code i written, please suggest me

//if (typeof window == 'undefined')
checkComments();

function checkComments()
{
var cmnt=current.comments;
var len=cmnt.toString().trim().length;
if(len>0)
{
var referBackKB = new GlideRecord('kb_knowledge');
referBackKB.addQuery('sys_id',current.document_id);
referBackKB.query();
if(referBackKB.next())
{
referBackKB.u_refer_back = true;
referBackKB.setWorkflow(false);
referBackKB.update();
}
var app = new GlideRecord('sysapproval_approver');
app.addQuery('state','requested');
app.addQuery('sysapproval',current.sysapproval);
app.queryNoDomain();

//gs.addInfoMessage('count='+app.getRowCount());
while(app.next())
{
current.state ='not_required';

// app.state ='requested';
current.update();
}

action.setRedirectURL(current);
//current.update();
//action.setRedirectURL('https://'+gs.getProperty('instance_name')+'.service-now.com/kb_knowledge_list.do');
}
else
{
current.setAbortAction(true);
gs.addInfoMessage("Please fill in the Reason for Refer Back in the Comments");
action.setRedirectURL(current);
}
}