- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2022 12:07 AM
Hey Community,
I have a requirement to create a UI Action to Open a related case.
1. Create a UI Action on the incident form and workspace that directs the user back to the related case
2. The UI action should be named 'Contact Customer'
3. Return error 'There is no related case' if no related case exists.
I need some assistance with the script please.
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2022 01:31 AM
Hi,
Something like this
I hope this will benefit you and you can mark my response as correct and helpful to close the thread since I provided the script.
You can do further debugging if there are some challenges
Script Include: It should be client callable
var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkRecordPresent: function(){
var sysId = this.getParameter('sysparm_sysId');
var gr = new GlideRecord('sn_customerservice_case');
gr.addEncodedQuery('incident=' + sysId);
gr.query();
if(gr.next()){
return gr.getUniqueValue();
}
else
return '';
},
type: 'checkRecords'
});
Script:
function openCase(){
// GlideAjax here
var ga = new GlideAjax('checkRecords');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_userID', g_form.getUniqueValue());
ga.getXMLAnswer(function(answer){
if(answer != ''){
var url = '/sn_customerservice_case.do?sys_id=' + answer;
g_navigation.open(url,'_blank');
}
else{
g_form.addErrorMessage('There is no related case');
}
});
}
Workspace client script:
function onClick(g_form) {
var ga = new GlideAjax('checkRecords');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_userID', g_form.getUniqueValue());
ga.getXMLAnswer(function(answer){
if(answer != ''){
var url = '/sn_customerservice_case.do?sys_id=' + answer;
open(url);
}
else{
g_form.addErrorMessage('There is no related case');
}
});
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2022 12:12 AM
Hi,
so on click of UI action it should redirect to case
You can use GlideAjax to check if there is any case for this incident and based on that redirect or show error message
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2022 12:16 AM
Hi,
like this
I assume you are comfortable in scripting
Script section:
var url = ''; // form the url
g_navigation.open(url,'_blank');
Workspace client script section:
var url = ''; // form the url
open(url);
for redirection use this
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2022 12:19 AM
Hi Ankur,
Not comfortable with scripting, still learning 🙂
Must I use the code as you have done it in the screenshot?
could you assist me with both scripts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2022 01:31 AM
Hi,
Something like this
I hope this will benefit you and you can mark my response as correct and helpful to close the thread since I provided the script.
You can do further debugging if there are some challenges
Script Include: It should be client callable
var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkRecordPresent: function(){
var sysId = this.getParameter('sysparm_sysId');
var gr = new GlideRecord('sn_customerservice_case');
gr.addEncodedQuery('incident=' + sysId);
gr.query();
if(gr.next()){
return gr.getUniqueValue();
}
else
return '';
},
type: 'checkRecords'
});
Script:
function openCase(){
// GlideAjax here
var ga = new GlideAjax('checkRecords');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_userID', g_form.getUniqueValue());
ga.getXMLAnswer(function(answer){
if(answer != ''){
var url = '/sn_customerservice_case.do?sys_id=' + answer;
g_navigation.open(url,'_blank');
}
else{
g_form.addErrorMessage('There is no related case');
}
});
}
Workspace client script:
function onClick(g_form) {
var ga = new GlideAjax('checkRecords');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_userID', g_form.getUniqueValue());
ga.getXMLAnswer(function(answer){
if(answer != ''){
var url = '/sn_customerservice_case.do?sys_id=' + answer;
open(url);
}
else{
g_form.addErrorMessage('There is no related case');
}
});
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader