Configure an action item
For an action function to work, you must create an action item to associate with the action function. Action items define what the action function is and how it works.
Before you begin
Role required: admin
About this task
Use action items to define what an action function does when a user uses that function. The following steps detail creating an action without parameters. To create a parametrized action item, see Configure an action item with parameters.
Procedure
Example
The following example uses a script to assign a task to the current user, using the
SMTask object. The first if statement checks to see that the input
is a valid wm_task record and ends the script if it is not. The
second if statement contains code that assigns the task to the
current user, if the user has permission, as determined by the
canAssignToSelf method. This action was done as a script rather
than an update so that these checks could be included.
(function WriteBackAction(parm_input, parm_variable) {
var smTask = new global.SMTask();
var work_order_task_id = parm_variable['sys_id'];
var wotGR = new GlideRecord("wm_task");
if (!wotGR.get(work_order_task_id)) {
gs.error("wot_assign_to_me write-back action - failed to find work order task");
gs.addErrorMessage(gs.getMessage("Task assignment failed."));
return;
}
if (smTask.canAssignToSelf(wotGR))
smTask.assignToMe(gs.getUserID(), work_order_task_id);
else
gs.addErrorMessage(gs.getMessage("Not a valid task assignment."));
})(parm_input, parm_variable);
The following example uses a script to perform a navigation completion functionality
after an action is performed. Enter actionResult as the function
and then define setRedirectionInfo(gr.getUniqueValue(),
gr.getTableName() to specify where to navigate to, once the action is
performed.
(function WriteBackAction(parm_input, parm_variable, actionResult) {
var gr = new GlideRecord('incident');
gr.get(parm_variable['sys_id']);
gr.short_description = 'Updated by Scripted Action';
gs.addInfoMessage(gs.getMessage("This is the First success message"));
gs.addInfoMessage(gs.getMessage("This is the Second success message"));
gs.addInfoMessage(gs.getMessage("This is the Third success message"));
gs.addInfoMessage(gs.getMessage("This is the Forth success message"));
gr.update();
actionResult.setRedirectionInfo(gr.getUniqueValue(), gr.getTableName());
})(parm_input, parm_variable, actionResult);
sys_id in the Incident [incident] table.(function WriteBackAction(parm_input, parm_variable, actionResult) {
var targetTableName = "incident";
var targetTableRecordSysId = "37aa099533b352102ed2923fad5c7b09";
var inputName = "input2"; // input2 stands for the input's name. The input type must be "Attachment"
actionResult.addAttachment(inputName, targetTableName, targetTableRecordSysId);
})(parm_input, parm_variable, actionResult);
If you use parameters for the action item, you can call them in the script. The call
in the script must match the parameter name exactly. For example, if the parameter
name is wb_wot_reject_work_note, as in the first script above, you can call it in
the script using gr.work_notes =
input.wb_wot_reject_work_note;.
What to do next
Associate the action item with an action function, see action function.
Associate action steps to an action item, see Configure action steps within an action item.