Plz, check this one script... It will meet all conditions for the above requirement. Please let me know if I'm wrong...! It will also work on multiple child incidents. Should all the child incident state "Closed", then n only then this script will allow to change the parent incident state to "Closed". Otherwise not. BR: Before, Operation: Updates, Filter Condition: State changes to close. Script: (function executeRule(current, previous /*null when async*/ ) { var gr = new GlideRecord('incident'); gr.addQuery('parent_incident', current.sys_id); gr.query(); while (gr.next()) { if (gr.state != '7') { gs.addErrorMessage('Plz Close the all child incident n then u can change the state'); current.setAbortAction(true); action.setRedirectURL(current); } } })(current, previous);
I have received similar requirement but when I used the business rule after abort action it was not staying on the same page. Again I have used ui action and it's fine. Could you please let me know what could be the reason
Hi Ravi, i have written the same code, however i am unable to close the child incident as well. Am i making any error in the code? (function executeRule(current, previous /*null when async*/) { var Inc=new GlideRecord('incident'); Inc.addQuery('parent_incident',current.sys_id); Inc.query(); if(Inc.next){ if(Inc.state=='7'){ gs.addInfoMessage("the child incident is closed"); current.setAbortAction(false); } else{ gs.addErrorMessage("the child incident is not closed"); current.setAbortAction(true); } } })(current, previous);
I found two bugs: 1) you need to add parentheses ( ) next to next method. It should be like this: if(Inc.next()) 2) your 'Inc' variable is written with CAPITAL 'I' which is not allowed for variable name. Change it to 'inc'.
If we have multiple child incidents in open state under that parent incident, then we need to first close all these child incidents to close the parent incident right? So how close the child incidents?
Hi Ravi, a quick question. Why do we need IF ELSE? can't we just write if (grinc.state != '7') current.setAbortAction(true);? Also in case of more than one children, can we get the count of child records where the ('parent_incident', current.sys_id) and child (grinc.state != '7') instead of looping? If yes, appreciate if you can share the logic. Thank you
Hi Ravi, i didn't get the script clearly.... because, you have written business rules in incident table, then why are you glide recording incident table again??? And also inc.state ==7 , this means, which state it is taking in incident table like, parent incident state or child incident state.....if it is taking child incident state, then how to we know it is taking child incident state
Hi Ravi , Thanks for sharing the interview questions One update in the script In else condition please update the error message syntax Three times message is added ,due to this else condition is not working and it shows as invalid update. Thank you
@@learnservicenowwithravi Hi Ravi , below is the script. When before update record Cond: State changes (function executeRule(current, previous /*null when async*/) { var inc = new GlideRecord('incident'); inc.addQuery('parent_incident', current.sys_id); inc.query(); if (inc.next()) { if (inc.state == '7') { gs.addInfoMessage("This is child incident and the state is close "); current.setAbortAction(false); // misson successfull } else { gs.addErrorMessage("Child Incident is not closed,please close the child incident before closing he parent "); current.setAbortAction(true); } } })(current, previous);
Hello sir , 5 may of my CSA exam so, you would like to provide me important questions for crack my CSA exam . because your explanation is very good 👍👍 i like that.please sir provide me important questions for CSA (service now) Exam🙏🙏
Plz check this one script... It will meet all conditions of the above requirements. correct me if I'm wrong... ! BR: Before, Operation: Updates, Filter Condition: State changes to close. Script: (function executeRule(current, previous /*null when async*/ ) { var gr = new GlideRecord('incident'); gr.addQuery('parent_incident', current.sys_id); gr.query(); while (gr.next()) { if (gr.state != '7') { gs.addErrorMessage('Plz Close the all child incident n then u can change the state'); current.setAbortAction(true); action.setRedirectURL(current); } } })(current, previous);
not sure why but else condition doesn't work var grinc = new GlideRecord('incident'); grinc.addQuery('parent_incident', current.sys_id); grinc.query(); if (grinc.next()) { if (grinc.state == '7') gs.addInfoMessage("child is in closed state"); current.setAbortAction(false); } else { gs.addErrorMessage("child is NOT in closed state"); current.setAbortAction(true); } Could you please validate
var grinc = new GlideRecord('incident'); grinc.addQuery('parent_incident', current.sys_id); grinc.query(); if (grinc.next()) { if (grinc.state == '7'){ gs.addInfoMessage("child is in closed state"); current.setAbortAction(false); } else { gs.addErrorMessage("child is NOT in closed state"); current.setAbortAction(true); } } try this, you've missed to add braces after second if and closing of else.
And also, this example is for one child incident......if one incident have multiple child incidents then how we can write script ravi? I mean, how we can write query condition
Thanks ravi for making such kind of videos. Its will be very helpful. Looking forward for more videos...
It's my pleasure
Best video. We need more
nice explanation
Thanks for liking
Thanks ravi for making thesekind of usecases. Looking forward for more vedios. 😊
My pleasure 😊
Plz, check this one script... It will meet all conditions for the above requirement.
Please let me know if I'm wrong...!
It will also work on multiple child incidents. Should all the child incident state "Closed", then n only then this script will allow to change the parent incident state to "Closed". Otherwise not.
BR: Before, Operation: Updates,
Filter Condition: State changes to close.
Script:
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord('incident');
gr.addQuery('parent_incident', current.sys_id);
gr.query();
while (gr.next()) {
if (gr.state != '7') {
gs.addErrorMessage('Plz Close the all child incident n then u can change the state');
current.setAbortAction(true);
action.setRedirectURL(current);
}
}
})(current, previous);
Perfect
I have received similar requirement but when I used the business rule after abort action it was not staying on the same page.
Again I have used ui action and it's fine. Could you please let me know what could be the reason
Share your script
Hi Ravi,
i have written the same code, however i am unable to close the child incident as well. Am i making any error in the code?
(function executeRule(current, previous /*null when async*/) {
var Inc=new GlideRecord('incident');
Inc.addQuery('parent_incident',current.sys_id);
Inc.query();
if(Inc.next){
if(Inc.state=='7'){
gs.addInfoMessage("the child incident is closed");
current.setAbortAction(false);
}
else{
gs.addErrorMessage("the child incident is not closed");
current.setAbortAction(true);
}
}
})(current, previous);
Let me check
I found two bugs: 1) you need to add parentheses ( ) next to next method. It should be like this: if(Inc.next())
2) your 'Inc' variable is written with CAPITAL 'I' which is not allowed for variable name. Change it to 'inc'.
If we have multiple child incidents in open state under that parent incident, then we need to first close all these child incidents to close the parent incident right? So how close the child incidents?
Check out all child linked to single parent and then close all child and then close parent
Hi Ravi, a quick question. Why do we need IF ELSE? can't we just write if (grinc.state != '7') current.setAbortAction(true);? Also in case of more than one children, can we get the count of child records where the ('parent_incident', current.sys_id) and child (grinc.state != '7') instead of looping? If yes, appreciate if you can share the logic. Thank you
Sir can you tell me how I convert knowledge article in service into the json body
Very soon will bring video
Hi Ravi, i didn't get the script clearly.... because, you have written business rules in incident table, then why are you glide recording incident table again??? And also inc.state ==7 , this means, which state it is taking in incident table like, parent incident state or child incident state.....if it is taking child incident state, then how to we know it is taking child incident state
I glide because i have to check if parent incident has a child..i glide only once because i need to get parent_incident field..
Hi Ravi, will it work the same if we have an incident task instead of a child incident?
Yes
hi Ravi, Why the info message or Error message haven't displayed?
Which time stamp can you tell
ThE messages you mentioned in the code did not appear like this is child incident....😊that's ok... thanks for the video.
Hi Ravi ,
Thanks for sharing the interview questions
One update in the script
In else condition please update the error message syntax
Three times message is added ,due to this else condition is not working and it shows as invalid update.
Thank you
Add info message as well
Share your script
@@learnservicenowwithravi
Hi Ravi , below is the script.
When before update record
Cond:
State changes
(function executeRule(current, previous /*null when async*/) {
var inc = new GlideRecord('incident');
inc.addQuery('parent_incident', current.sys_id);
inc.query();
if (inc.next()) {
if (inc.state == '7') {
gs.addInfoMessage("This is child incident and the state is close ");
current.setAbortAction(false); // misson successfull
} else {
gs.addErrorMessage("Child Incident is not closed,please close the child incident before closing he parent ");
current.setAbortAction(true);
}
}
})(current, previous);
explaination is good, but one video for one scenario may take time. Please include three or four in one video
Sure noted 😀
Agree.. we can’t wait for ages to get decent questions 😂
how to get backend names all fields in doubble click
You need to install sn untill from chrome store
Hello sir , 5 may of my CSA exam so, you would like to provide me important questions for crack my CSA exam . because your explanation is very good 👍👍
i like that.please sir provide me important questions for CSA (service now) Exam🙏🙏
drive.google.com/file/d/1P2c5vc1zJvi1vzllEJFLcnl3ySsGw6RP/view?usp=drivesdk
@@learnservicenowwithravi Sir that is enough of a question for cracking the CSA exam.??
Plz check this one script... It will meet all conditions of the above requirements.
correct me if I'm wrong... !
BR: Before, Operation: Updates,
Filter Condition: State changes to close.
Script:
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord('incident');
gr.addQuery('parent_incident', current.sys_id);
gr.query();
while (gr.next()) {
if (gr.state != '7') {
gs.addErrorMessage('Plz Close the all child incident n then u can change the state');
current.setAbortAction(true);
action.setRedirectURL(current);
}
}
})(current, previous);
Perfect
can you please share your google drive link?
Its in group description
+1
not sure why but else condition doesn't work
var grinc = new GlideRecord('incident');
grinc.addQuery('parent_incident', current.sys_id);
grinc.query();
if (grinc.next()) {
if (grinc.state == '7')
gs.addInfoMessage("child is in closed state");
current.setAbortAction(false);
} else {
gs.addErrorMessage("child is NOT in closed state");
current.setAbortAction(true);
}
Could you please validate
var grinc = new GlideRecord('incident');
grinc.addQuery('parent_incident', current.sys_id);
grinc.query();
if (grinc.next()) {
if (grinc.state == '7'){
gs.addInfoMessage("child is in closed state");
current.setAbortAction(false);
} else {
gs.addErrorMessage("child is NOT in closed state");
current.setAbortAction(true);
}
}
try this, you've missed to add braces after second if and closing of else.
And also, this example is for one child incident......if one incident have multiple child incidents then how we can write script ravi? I mean, how we can write query condition
Use while condition instead of if
I just love the way u teach us for us.very thanks for the info
Please help me ravi regarding this