UI Action: Can I pass a value from the client function to the server function?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2015 12:50 PM
UI Action with Client == true
Current table is incident.
Intention is to take input via user confirmation in the client-side function & pass a value based upon that into a problem record that will be submitted in the server-side function.
I tried declaring a variable outside the functions and setting its value in the client-side function but its value is apparently not available to the server-side function.
I've tried doing a g_form_setValue in the client-side function to get a value into the current incident & than use that value to set a value in the new problem record. To save that to the incident, I used
gsftSubmit(document.getElementById('sysverb_update_and_stay'));
but it doesn't perform an update.
I followed that with
gsftSubmit(null, g_form.getFormElement(), 'create_problem');
to call the 'Action name' set in the UI Action but the problem is not created.
The UI action works fine if I don't bother with the second "confirm" or try to do the first gsftSubmit. Script with both is as follows.
//client-side 'onClick' function
function confirmProblem(){
var answer = confirm('Are you certain you want to create a problem record for this incident?');
if (!answer){
return false; //abort problem creation
}
var assignGroup = g_form.getReference('assignment_group');
var notify = confirm('Instead of waiting until you have modified the problem, do you want to notify the ' + assignGroup.name + " group immediately?");
alert("notify: " + notify);
if (notify){
g_form.setValue('u_problem_notify_on_create', true);
alert("notify on create: " + g_form.getValue('u_problem_notify_on_create'));
}
gsftSubmit(document.getElementById('sysverb_update_and_stay'));
alert("just before the second gsftSubmit");
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'create_problem'); //MUST call the 'Action name' set in this UI Action
alert("just after the second gsftSubmit");
}
createProblem();
//server-side fn
function createProblem(){
var prob = new GlideRecord("problem");
prob.short_description = current.short_description;
prob.cmdb_ci = current.cmdb_ci;
prob.priority = current.priority;
prob.impact = current.impact;
prob.urgency = current.urgency;
prob.description = current.description;
prob.assignment_group = current.cmdb_ci.u_level_3_support_group;
prob.u_notify_on_create = current.u_problem_notify_on_create;
var sysID = prob.insert();
current.problem_id = sysID;
var mySysID = current.update();
gs.addInfoMessage("Problem " + prob.number + " created");
action.setRedirectURL(prob);
action.setReturnURL(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2020 10:24 PM
Thanks
I was scratching my head about the Global Variable in server/client side issue for a while, but this explained it perfectly!
Cheers,
- MH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 06:35 AM
Hi Douglas, I haven't found a way to use parameter.
But as a workaround you can create another inactive UI Action with a different "Action name".
Then you call one or the other in your main UI Action.
Example below:
function create_prob_call(){
if(confirm("Do you want to add the incident affected CIs in the problem?")){
return gsftSubmit(null, g_form.getFormElement(), 'create_prob_from_inc');
}
else{
//We call the inactive UI Action with this name. This is a workaround because we can't push a parameter
return gsftSubmit(null, g_form.getFormElement(), 'create_prob_from_inc_no_ci');
}
}