- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2019 12:51 AM
Good day everyone,
Can anyone explain me the meaning of parent.sys_id and sys_id which we write as the second parameter in the addQuery(). and when do we use this ?
Thanks
Kevin
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2019 05:53 AM
Hi There,
for e.g: Scenario like
Look on incident and incident task table
Find how many tasks are present to particular incident
then you should write BR on incident table like
see bellow code
gr.addQuery();
first param:incident is a field on incident task table which contain the sys_id of incident
second param: current.sys_id is sys_id of current incident SO here we should compare with this method,
In this case you should use the current.sys_id.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr=new GlideRecord('incident_task');
gr.addQuery('incident',current.sys_id);
gr.query();
while(gr.next())
{
gs.addInfoMessage(gr.number);//give task number
}
})(current, previous);
Now Again
Take Look on problem table and find out any change is related to same problem then,
Write BR script like,
see
first param: sys_id (current prob sys_id)
second param: current.parent(reference of change) it is also giving the sys_id(becouse it is refernce field)
if the change sys_id is present into problem table then it will give result
(function executeRule(current, previous /*null when async*/) {
var gr=new GlideRecord('change_request');
gr.addQuery('sys_id',current.parent);//both will give you sys_id if same then it will excecute
gr.query();
while(gr.next())
{
gs.addInfoMessage(gr.number);//will get change number if present
}
})(current, previous);
let me know if any doubt
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2019 12:52 AM
Hi Kevin,
Where are you using this script? based on that definition of parent will come
Is this you are using in list control omit new/edit condition?
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
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-16-2019 01:11 AM
I am not using this anywhere I just want to know what does it mean and when to use it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2019 01:31 AM
Hi Kevin,
One scenario for this could be having parent incident and child incident. on incident form there should be parent field. this indicates whether this is a child incident
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
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-16-2019 05:53 AM
Hi There,
for e.g: Scenario like
Look on incident and incident task table
Find how many tasks are present to particular incident
then you should write BR on incident table like
see bellow code
gr.addQuery();
first param:incident is a field on incident task table which contain the sys_id of incident
second param: current.sys_id is sys_id of current incident SO here we should compare with this method,
In this case you should use the current.sys_id.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr=new GlideRecord('incident_task');
gr.addQuery('incident',current.sys_id);
gr.query();
while(gr.next())
{
gs.addInfoMessage(gr.number);//give task number
}
})(current, previous);
Now Again
Take Look on problem table and find out any change is related to same problem then,
Write BR script like,
see
first param: sys_id (current prob sys_id)
second param: current.parent(reference of change) it is also giving the sys_id(becouse it is refernce field)
if the change sys_id is present into problem table then it will give result
(function executeRule(current, previous /*null when async*/) {
var gr=new GlideRecord('change_request');
gr.addQuery('sys_id',current.parent);//both will give you sys_id if same then it will excecute
gr.query();
while(gr.next())
{
gs.addInfoMessage(gr.number);//will get change number if present
}
})(current, previous);
let me know if any doubt
thanks