- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 05:35 AM
Hi Everyone,
I have a particular requirement which is little complicated. My requirement is like this :
1. When a user populates a Configuration item field on requested item, then the item should go for approval to the manager of the assigned to user of that configuration item.
2. If by chance that assigned to user does not have manager , then pop should come saying that " Assigned to user does not have manager . Do you still want to proceed ? " . If I select Yes then item should get auto approve or else if select no then page should refresh with configuration item field as empty .
Currently I am trying to achieve this using onChange client script. Please suggest if anyone has some solution for above requirement.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 08:59 AM - edited 04-28-2024 09:01 AM
1)For your First requirement write a After update BR:
When to run:
When configuration item assigned to manager is not empty (dot walk)
Write script to trigger approval record.
2)For your 2nd requirement write a onchange client script:
Client script
onChange of Configuration item.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var as = new GlideAjax('Configuration_manager');
as.addParam('sysparm_name', 'ci_manager');
as.addParam('sysparm_sys_id', newValue);
as.getXML(createout);
function createout(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert(answer);
if(answer == ''){//if manager is empty
var gm = new GlideModal("CustomUIforCI");
gm.setTitle("Assigned to user does not have manager . Do you still want to proceed ? ");
gm.render();
}
}
}
Script include:
Set client callable to true
var Configuration_manager = Class.create();
Configuration_manager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
ci_manager: function(){
var gr=new GlideRecord('cmdb_ci');
gr.addQuery('sys_id',this.getParameter('sysparm_sys_id'));
gr.query();
if(gr.next()){
var answer = gr.assigned_to.manager;
}
return answer;
},
type: 'Configuration_manager'
});
Ui page:
HTML in Ui Page
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<span>
<g:sc_button id="test" title="title" label="Yes" onclick="Func1()" />
<g:sc_button id="test" title="title" label="No" onclick="Func2()" /> </span>
</j:jelly>
Client script in Ui page
function Func1() {
var gdw = GlideDialogWindow.get();
g_form.setValue('state', 3);//set approval to approved or any action that you want to do when yes is pressed
g_form.save();
gdw.destroy();
}
function Func2() {
var gdw = GlideDialogWindow.get();
g_form.setValue('configuration_item', ' ');
g_form.save();
gdw.destroy();//making ci to be empty if no is selected
}
Mark my answer correct/helpful if it resolved your query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 08:59 AM - edited 04-28-2024 09:01 AM
1)For your First requirement write a After update BR:
When to run:
When configuration item assigned to manager is not empty (dot walk)
Write script to trigger approval record.
2)For your 2nd requirement write a onchange client script:
Client script
onChange of Configuration item.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var as = new GlideAjax('Configuration_manager');
as.addParam('sysparm_name', 'ci_manager');
as.addParam('sysparm_sys_id', newValue);
as.getXML(createout);
function createout(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert(answer);
if(answer == ''){//if manager is empty
var gm = new GlideModal("CustomUIforCI");
gm.setTitle("Assigned to user does not have manager . Do you still want to proceed ? ");
gm.render();
}
}
}
Script include:
Set client callable to true
var Configuration_manager = Class.create();
Configuration_manager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
ci_manager: function(){
var gr=new GlideRecord('cmdb_ci');
gr.addQuery('sys_id',this.getParameter('sysparm_sys_id'));
gr.query();
if(gr.next()){
var answer = gr.assigned_to.manager;
}
return answer;
},
type: 'Configuration_manager'
});
Ui page:
HTML in Ui Page
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<span>
<g:sc_button id="test" title="title" label="Yes" onclick="Func1()" />
<g:sc_button id="test" title="title" label="No" onclick="Func2()" /> </span>
</j:jelly>
Client script in Ui page
function Func1() {
var gdw = GlideDialogWindow.get();
g_form.setValue('state', 3);//set approval to approved or any action that you want to do when yes is pressed
g_form.save();
gdw.destroy();
}
function Func2() {
var gdw = GlideDialogWindow.get();
g_form.setValue('configuration_item', ' ');
g_form.save();
gdw.destroy();//making ci to be empty if no is selected
}
Mark my answer correct/helpful if it resolved your query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 10:20 PM
Hi @Ramz ,
If I click on "yes" and I don't want to auto approve rather I want to send for approval to assigned to of configuration item ( Do not want to send to manager rather send it to assigned to user only).
Then what should be my steps.
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 07:35 AM - edited 04-29-2024 07:40 AM
Hi @Abhijit Das7 ,
Create a new field Yes/No on the form and pass the value of UI page to the field
So when yes is clicked just pass the value of yes to the variable and save the form in client script- trigger your approval using after update BR:
function Func1() {
var gdw = GlideDialogWindow.get();
g_form.setValue('new_variable', 'yes ');
g_form.save();//Just pass the value and save the form so that you can trigger approval using after update BR
gdw.destroy();
}
function Func2() {
var gdw = GlideDialogWindow.get();
g_form.setValue('new_variable', 'no ');
g_form.setValue('configuration_item', ' ');
g_form.save();
gdw.destroy();//making ci to be empty if no is selected
}
Business rule:
After Update:
When to run:
When configuration item assigned to manager is empty (dot walk)
and
new variable value changes to Yes
-also make sure to include conditions/check in script to ensure approval will be only triggered once
Script:
Call approval table and trigger approval to assigned to of CI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 07:47 AM
Hi @Abhijit Das7 ,
Let me know if this solution worked for you or if you have any query
Please mark my answer correct/helpful if it resolved your query