- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 10:26 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2016 02:56 AM
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()
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();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 10:35 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 11:43 PM
Hi Pradeep
Thank you so much ..
i have got some idea about how it works..
if it possible do you have any other example which can elaborate more about this..

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 11:53 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2016 12:30 AM
Hi Sandeep,
That is a really very important question to have inside a Snow developer's mind. I will try my best to make you understand with my own code :
The above is a UI action, a button named "Refer Back" which is present for Approvers so that they can redirect the incident,change,task etc. to certain users if they feel the information is not enough for their approval.
Now for the button to behave as both Server side and Client side, we just need to check the "Client" check box. If unchecked it default behaves like a Server side script. On checking "Client" field you get a field "Onclick" to be shown just above the Condition field (See screenshot). Define any function in this field. Now this function body is defined in the Script field. What it means is that On-click of this button we actually want to call this function ( referBack() in my screenshot) and execute the codes inside this function. It this function where we write certain client side codes to be executed like making fields mandatory false or true, state changes, making fields read only true or false,etc. The classic case is when you want to click a button to make an update to a record, but only if the user has provided the correct input first. To bring into action this correct inputs are done we need client side running scripts and these are the scripts written inside the Onclick function. See my code below and do read the comments in the code lines :
- function referBack(){ // This function is called when we click on the button to execute certain client side codes.
- if (g_form.getValue('comments') == '') {
- // Remove any existing field message, set comments mandatory, and show a new field message
- try {
- g_form.hideFieldMsg('comments'); // Client side execution : hiding field messages in Comments field if any
- } catch(e) {}
- g_form.setMandatory('comments', true); // Client side execution : setting mandatory
- g_form.showFieldMsg('comments', getMessage('Please enter a comment why would you like to refer back'), 'error'); // If you want the approver to describe the changes he needs. Client side execution
- return false; // Abort submission
- }
- gsftSubmit(null, g_form.getFormElement(), 'refer_back'); // MUST call the 'Action name' set in this UI Action
- }
- // Code that runs without 'onclick' . This is the server side code all below and outside the Onclick function because you need to execute this on the server side
- if (typeof window == 'undefined')
- serverReopen();
- function serverReopen() {
- var chg = new GlideRecord("change_request");
- chg.addQuery('sys_id' , current.getValue('sysapproval'));
- chg.query();
- if(chg.next())
- {
- chg.state = 1; //changing the state of change req back to 'Open' from 'Approval Requested'
- current.state = 'not requested'; // you might want to change the state of approval in the sysapproval_approver table from "requested" to "Not requested"
- }
- chg.update();
- current.update();
- gs.addInfoMessage(gs.getMessage("Request is referred back for changes")); // user friendly msg on success
- action.setRedirectURL(current);
- }
I believe this helps you and makes your understanding even stronger. After all you are a SNOW Developer.
Thanks,
Arnab
Please mark Correct/Helpful according to the worthiness of my explaination. Thank you in advance.