- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 02:07 AM
Hello
I have a task to fill field "short_description" (on every incident, where short_description is empty) on "Incident" table with "producer" field name from table "sc_item_produced_record", by using background script, but im new in scripting and i stucked.
Short description from incident must be filled with this field
I started like this, but i have no clue how to go on
Please, assist.
Regards
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 02:34 AM
Hello @Miko_aj Buczek ,
So current is an object which you can use when you are writing the same script in business rule .
But in your case it is background script so current object is not accessible here so what you can do is for testing purpose copy the sys_id of a sample incident record like below
1)Go to incident table and search for your incident record and do a right click on the incident number and click on copy sys_id(see below screenshot)
Then come to your back ground script and paste your incident sys_id in the place of current.sys_id;
var gr = new GlideRecord('incident');
gr.addEncodedQuery('short_descriptionISEMPTY');
gr.addQuery('sys_id','your_incident_sys_id');
gr.query();
if(gr.next())
{
var pr = new GlideRecord('sc_item_produced_record');
pr.addQuery('task', gr.sys_id);
pr.query();
if(pr.next()) {
gr.short_description = pr.producer.name.toString();
gr.update();
}
}
HOPE THIS HELPS
Mark my answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 03:42 AM
As per new community platform you can mark multiple responses as correct.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 02:34 AM
Hello @Miko_aj Buczek ,
So current is an object which you can use when you are writing the same script in business rule .
But in your case it is background script so current object is not accessible here so what you can do is for testing purpose copy the sys_id of a sample incident record like below
1)Go to incident table and search for your incident record and do a right click on the incident number and click on copy sys_id(see below screenshot)
Then come to your back ground script and paste your incident sys_id in the place of current.sys_id;
var gr = new GlideRecord('incident');
gr.addEncodedQuery('short_descriptionISEMPTY');
gr.addQuery('sys_id','your_incident_sys_id');
gr.query();
if(gr.next())
{
var pr = new GlideRecord('sc_item_produced_record');
pr.addQuery('task', gr.sys_id);
pr.query();
if(pr.next()) {
gr.short_description = pr.producer.name.toString();
gr.update();
}
}
HOPE THIS HELPS
Mark my answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 03:05 AM
Hi,
Can you amend the line in your code:
it should be :
var grInc= new GlideRecord('incident');
grInc.addEncodedQuery('short_descriptionISEMPTY');
grInc.query();
while(grInc.next())
{
var prod = new GlideRecord('sc_item_produced_record');
prod.addQuery('task', gr.sys_id);
prod.query();
if(prod.next()) {
grInc.short_description = prod.producer.name;
grInc.update();
}
}
Note: Current refers to current table. (Where you have written your script).