- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 08:15 AM
Hello All,
I have written a Ui Action code for both serve and client side code is not working properly?
Below is the code and screen shot, please tell me the issue in the below code.
function mandatory()
{
g_form.setMandatory('u_technology_group',true);
gsftSubmit(null, g_form.getFormElement(), "isnew");
}
if(typeof window == 'undefined')
runBusRuleCode();
//Server-side function
function runBusRuleCode(){
var name = gs.getUser().getFullName();
current.assigned_to = name;
current.state =6;
current.update();
action.setRedirectURL(current);
}
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 08:58 AM
As Brendan and Dave mentioned, you are not very specific as to what "is not working properly", which makes it a bit difficult to help you out.
However, that being said, there are some obvious questions and issues:
1. what is in the "Action name" field of the UI Action? I'm assuming it is "isnew" because of line 4 in your code. These 2 must match.
2. I like to prefix custom JavaScript function names with "u_" just in case ServiceNow adds functions with the same name. This limits the problem.
3. "u_mandatory();" should be in the "Onclick" field and not in the "Hint" field
4. when setting the "assigned_to" field, you need to use a sys_id and not the user's name
5. the following code should work for you now:
function u_mandatory() {
g_form.setMandatory('u_technology_group',true);
gsftSubmit(null, g_form.getFormElement(), "isnew");
}
if(typeof window == 'undefined')
u_runBusRuleCode();
//Server-side function
function u_runBusRuleCode(){
current.assigned_to = gs.getUserID();
current.state = 6;
current.update();
action.setRedirectURL(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 08:18 AM
you have client checked, but noting in the onclick, put in onclick Mandatory()
Also under link 9 you need to call your action name, server side
if(typeof window == 'undefined')
runBusRuleCode(); // you missed having the function definition
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'action name'); //MUST call the 'Action name' set in this UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 08:26 AM
As Brendan mentioned, there's a few issues here:
- mandatory() needs to be in "onclick", not in "hint".
- you are using GlideSystem which is server-side in client-side code - that ought to go into a Script Include to be called it from your client action?
- You're not really explaining what outcome you're after - other than your code working. If you were to explain why you're trying to do something, perhaps alternative approaches could be explored
- "code is not working properly?" isn't really a particularly verbose problem definition.
Have you attended our script course at all? http://www.servicenow.com/services/training-and-certification/scripting-in-servicenow-training.html - we often look at this kind of coding and also some troubleshooting/debugging tools that could help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2017 05:08 AM
Hi, I have a one requirement,that is to crate a radio button on incident form, in that when ever the cursor on it its displays the how many users are view the particular incident record(like particular team members).and click on that it displays the those names(users name).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 08:58 AM
As Brendan and Dave mentioned, you are not very specific as to what "is not working properly", which makes it a bit difficult to help you out.
However, that being said, there are some obvious questions and issues:
1. what is in the "Action name" field of the UI Action? I'm assuming it is "isnew" because of line 4 in your code. These 2 must match.
2. I like to prefix custom JavaScript function names with "u_" just in case ServiceNow adds functions with the same name. This limits the problem.
3. "u_mandatory();" should be in the "Onclick" field and not in the "Hint" field
4. when setting the "assigned_to" field, you need to use a sys_id and not the user's name
5. the following code should work for you now:
function u_mandatory() {
g_form.setMandatory('u_technology_group',true);
gsftSubmit(null, g_form.getFormElement(), "isnew");
}
if(typeof window == 'undefined')
u_runBusRuleCode();
//Server-side function
function u_runBusRuleCode(){
current.assigned_to = gs.getUserID();
current.state = 6;
current.update();
action.setRedirectURL(current);
}