Ui Action for both server and client side code is not working properly?

Shantharao
Kilo Sage

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);

}

find_real_file.png

Thanks

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

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);


}


View solution in original post

4 REPLIES 4

brendanwilson84
Kilo Guru

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


Dave Smith1
ServiceNow Employee
ServiceNow Employee

As Brendan mentioned, there's a few issues here:


  1. mandatory() needs to be in "onclick", not in "hint".
  2. 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?
  3. 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
  4. "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.


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).


Jim Coyne
Kilo Patron

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);


}