UI action with server side and client side code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2016 01:42 PM
I am trying to create a UI action that will run some server side code and validate if a record a record exists. If it does I will update some fields if not abort.
Checking out Client & Server Code in One UI Action - ServiceNow Guru but i am still having some issues I am confused about the onClick and Action name fields I see how they are used in the example but i am still a little confused how to use them
function verify(){
var gr = new GlideRecord('dms_document');
gr.addQuery('u_demand','current.number');
gr.addQuery('type.name', 'foobar');
gr.query();
if(!gr.next()){
g_form.showFieldMsg('Document','ALERT YOU MUST DO SOMETHING','error');
}
}
if(typeof window == 'undefined')
commitRecord();
// commit record if verify function returned a record
function commitRecord(){
current.u_state = 20;
current.assignment_group.setDisplayValue('Team');
current.assigned_to = '';
current.update();
action.setRedirectURL(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2016 01:49 PM
Can you elaborate on what exactly you need? That article describes the scenario where you need to make some validations on the current form and then update the database(server-side) accordingly. But looking at your code, I don't see any client side validations/manipulations. So you could just omit the client callable feature here. But if you need client side functionality, there's one missing statement: gsftSubmit(null, g_form.getFormElement(), 'readyPR');
That function call is for the UI action again, but this time skipping the client side function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2016 10:43 PM
Hello,
Check the below settings. You need to check the client checkbox and should write the name of the function which is verify in this case in the OnClick field.
The action name should be unique with respect to UI action, but it can be anything. Make sure you do no give any space in the action name field.
Onclick function runs on the client side and the rest of the functions that are written executes in the server side.
You can use the entire block of code you used, I could not show it in the snapshot as I was not able to capture, but use the following code in the script section.
- function verify(){
- var gr = new GlideRecord('dms_document');
- gr.addQuery('u_demand','current.number');
- gr.addQuery('type.name', 'foobar');
- gr.query();
- if(!gr.next()){
- g_form.showFieldMsg('Document','ALERT YOU MUST DO SOMETHING','error');
- }
- }
- if(typeof window == 'undefined')
- commitRecord();
- // commit record if verify function returned a record
- function commitRecord(){
- current.u_state = 20;
- current.assignment_group.setDisplayValue('Team');
- current.assigned_to = '';
- current.update();
- action.setRedirectURL(current);
- }
Please Mark as Helpful if helps
Thanks
Prasun

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2016 11:14 PM
You are missing gsftSubmit line. Moreover current object is not available on client side. You are using current.number on client side. Instead use this g_form.getValue('number')
function verify(){
var gr = new GlideRecord('dms_document');
gr.addQuery('u_demand',g_form.getValue('number'));
gr.addQuery('type.name', 'foobar');
gr.query();
if(!gr.next()){
g_form.showFieldMsg('Document','ALERT YOU MUST DO SOMETHING','error');
}