Confirmation for UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2009 08:33 AM
I am trying to create a UI action that will prompt the user to verify they are taking the action they want and it was not a miss-click and then from there it will produce a new record. I was looking at Create a Confirmation UI Action and this will work if you are updating the current record but not if you are trying to create a new one from this record. Does anyone have any sugjestions? My current attempts are resulting in the confirmation box and then nothing.
I started with the below as the UI action and it works as a stand alone with no prompt.
var chrw = new GlideRecord("u_chrw_mybusiness");
chrw.u_affected_user = current.caller_id;
chrw.short_description = current.short_description;
chrw.description = current.description;
chrw.company = current.company;
chrw.u_transfer_ticket_number = current.sys_id;
chrw.state = '2';
var sysID = chrw.insert();
current.state = '4';
current.parent = sysID;
current.work_notes = "Transfered to Business Group";
var mySysID = current.update();
Packages.com.glide.ui.SysAttachment.copy("incident", current.sys_id, "u_chrw_mybusiness", chrw.sys_id);
gs.addInfoMessage("Busienss Task " + chrw.number + " created");
action.setRedirectURL(chrw);
action.setReturnURL(current);
I tried adding the below and seem to be stuck (this is now set as Client and Onclick is submitCreateBusinessTask():
function submitCreateBusinessTask(){
var conf = confirm('Do you really want to create a Business Task');
if(conf){
var chrw = new GlideRecord("u_chrw_mybusiness");
chrw.u_affected_user = current.caller_id;
chrw.short_description = current.short_description;
chrw.description = current.description;
chrw.company = current.company;
chrw.u_transfer_ticket_number = current.sys_id;
chrw.state = '2';
var sysID = chrw.insert();
current.state = '4';
current.parent = sysID;
current.work_notes = "Transfered to Business Group";
var mySysID = current.update();
Packages.com.glide.ui.SysAttachment.copy("incident", current.sys_id, "u_chrw_mybusiness", chrw.sys_id);
gs.addInfoMessage("Busienss Task " + chrw.number + " created");
action.setRedirectURL(chrw);
action.setReturnURL(current);
}
else{
//do nothing
}
}
- Labels:
-
Orchestration (ITOM)
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2009 09:02 AM
You're trying to make a UI action that needs to be server-side a client-side rule, and that's why it's not working. When you check the "client" box, you're then writing essentially an onSubmit script. This should help..
From: Create a Confirmation UI Action
Parameters:
Client: true
Form button: true
OnClick: submitConfirm();
function submitConfirm(){
var conf = confirm("Are you sure you want to submit a priority one incident?");
if(conf){
g_form.setValue('priority',1);
if(g_form.isNewRecord()){
gsftSubmit(gel('sysverb_insert'));
//gsftSubmit(gel('sysverb_insert_and_stay'));
}
else{
gsftSubmit(gel('sysverb_update'));
//gsftSubmit(gel('sysverb_update_and_stay'));
}
}
}
Since you're inserting an additional record via GlideRecord, I would put the script into a global business rule and call it using the AJAXEvaluateSynchronously() function. That way, you're only doing 1 server round trip, and you're not bringing the user's browser to its knees:
http://wiki.service-now.com/index.php?title=Client_Scripts#How_do_I_call_a_Business_Rule_from_a_Client_Script.3F
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2010 09:13 AM
This does everything except redirect the user to the new record after it's created. I would really prefer to hijack the user and send him off to the new record once it's saved..
When I stick the action.setRedirectURL in the business rule, and then update in the UI action after the business rule is complete, it returns me to the list view, not the new record.
When I try to put the redirect into the UI action, it fails because action.setRedirectURL only works in business rules..
Looking for a way to redirect the user from the client side UI action now..that's the last piece I need to get my action working the way it needs to work.
Appreciate any help, I've been knocking my head against walls on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2010 07:43 AM
I was able to complete this with a Server script include. Check out the below for the UI action and the script include. I am not expert on this I was just able to get it to work and thought I would share what I found.
UI action:
Client: True
On click: "Name of your function" eg. submitNewKBT()
function submitNewKBT(){
var conf = confirm('Do you really want to create a new Knowledge Submission?');
if(conf){
//Set the function to be called in script include
var ajax = new GlideAjax('MyNewKBTaskAjax');
//Update the blow line to match what you have in the script include.
ajax.addParam('sysparm_name','newKBT');
//Set additional parameters you may want to use in the script include
ajax.addParam('sysparm_sd', g_form.getValue('short_description'));
ajax.addParam('sysparm_desc', g_form.getValue('description'));
ajax.addParam('sysparm_numr', g_form.getValue('number'));
ajax.getXMLWait();
//response from ajax the Record;
var newrec = ajax.getAnswer();
//alert (newrec);
g_form.setValue('u_knowledge_submission', newrec);
//Update the current record and leave the current page.
gsftSubmit(document.getElementById('sysverb_update'));
}
}
Server Script Include:
Client Callable: True
//Make sure to update both of the below rows to include the name of the function called by GlideAjax
var MyNewKBTaskAjax = Class.create();
MyNewKBTaskAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
//this is from the line ajax.addParam('sysparm_name','newKBT'); in the UI action
newKBT: function (current){
//Build a new record
var grkb = new GlideRecord("kb_submission");
grkb.short_description = this.getParameter('sysparm_sd');
grkb.description = this.getParameter('sysparm_desc');
grkb.submitted_by = gs.getUserID();
grkb.parent.setDisplayValue(numr);
grkb.state = '0';
grkb.u_type = '1';
grkb.priority = '2';
grkb.assignment_group = '919acdf20a0a3c0e09c8306237fa0ae6';
var sysID = grkb.insert();
//set the redirect URL so we go to the new record
gs.setRedirect('kb_submission.do?sys_id=' + sysID);
gs.addInfoMessage("KB Submission " + grkb.number + " created");
//returning the sys_id so that we can save this into the current record.
return sysID;
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 12:07 AM
HI hunter,
I am trying to achieve a similar function as yours.But it is not working.
Requirement:
We have a ui action called 'Copy' in project_status table which will create a new record copying all the fields values from current record.
Whenever a user clicks the 'copy' button, there should be a confirmation message asking users whether they want to copy the attachment also.
If user clicks ok then new record should be created copy attachment from the current record along with all other field values.
If user clicks cancel, then new record should be created copying all the field values without copying attachm,ent from the current. Please refer the UI action script and Script include that i created for this from below.
UI action:
Client: True
On click: "Name of the function" eg. CopyStatusReport()
Server Script Include:
Client Callable: True
) New record is not getting created if Confirmation is yes.
2.) If Confirmation is cancel, New record is getting created but redirection is not going to the new record.
3.) Attachment is not copied to the new record.
PLease let me know if you can help me on this. Also let me know if you need more information on this.
Thanks in Advance,
Prasansha.